Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2yrs #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

2yrs #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions configs/mainmodel2.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
model:
name: mainmodel2
config:
meta_head: true
meta_head: false
nonhrv_channels:
# - IR_016
- VIS008
Expand All @@ -22,7 +22,7 @@ eval:
data:
num_workers: 16
root: /data/climatehack/
train_start_date: 2021-01-01 00:00:00
train_start_date: 2020-01-01 00:00:00
train_end_date: 2022-01-01 00:00:00
# subsets are randomly sampled from the full dataset using a seed of 21
# 0 means use all data
Expand Down
4 changes: 2 additions & 2 deletions data/random_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

# Think about whether all channels need to be flipped together or not
TRAIN_TRANSFORM = transforms.Compose([
# transforms.RandomErasing(p=0.25, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=0, inplace=True),
# transforms.RandomHorizontalFlip(p=0.5),
transforms.RandomErasing(p=0.25, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=0, inplace=True),
transforms.RandomHorizontalFlip(p=0.5),
# # transforms.RandomVerticalFlip(p=0.5),
# transforms.RandomApply([
# transforms.GaussianBlur(kernel_size=3, sigma=(0.1, 2.0)),
Expand Down
9 changes: 8 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ def _eval(dataloader, model, criterion=nn.L1Loss(), preds_save_path=None, ground
pv_features = pv_features.to(device, dtype=torch.float)
pv_targets = pv_targets.to(device, dtype=torch.float)

predictions = model(pv_features, features)
predictions0 = model(pv_features, features)

features[NONHRV.VIS008] = features[NONHRV.VIS008].flip(-1)

predictions1 = model(pv_features, features)

predictions = (predictions0 + predictions1) / 2
# predictions = predictions0

gt[i * dataloader.batch_size: (i + 1) * dataloader.batch_size] = pv_targets.cpu().numpy()
preds[i * dataloader.batch_size: (i + 1) * dataloader.batch_size] = predictions.cpu().numpy()
Expand Down
20 changes: 11 additions & 9 deletions submission/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def __init__(self, config) -> None:

self.meta_and_pv = MetaAndPv()

self.nonhrv_backbones = nn.ModuleList([models.resnet18() for i in range(len(self.nonhrv_channels))])
self.nonhrv_backbones = nn.ModuleList([models.resnext50_32x4d() for i in range(len(self.nonhrv_channels))])
for bone in self.nonhrv_backbones:
bone.conv1 = nn.Conv2d(12, 64, kernel_size=7, stride=2, padding=3, bias=False)
bone.conv1 = nn.Conv2d(6, 64, kernel_size=7, stride=2, padding=3, bias=True)
bone.fc = nn.Identity()

self.weather_backbones = nn.ModuleList([models.resnet18() for i in range(len(self.weather_channels))])
Expand All @@ -99,28 +99,29 @@ def __init__(self, config) -> None:

if self.meta_head:
self.linear1 = nn.Linear(
len(self.nonhrv_channels) * 512 +
len(self.nonhrv_channels) * 512 * 4 +
len(self.weather_channels) * 512 +
self.meta_and_pv.output_dim,
256)
else:
self.linear1 = nn.Linear(
len(self.nonhrv_channels) * 512 +
len(self.nonhrv_channels) * 512 * 4 +
len(self.weather_channels) * 512 +
12 + 12,
256)
384, bias=True)

self.linear2 = nn.Linear(256, 256, bias=True)
self.linear3 = nn.Linear(256, 48)
self.r = nn.ReLU(inplace=True)
self.linear2 = nn.Linear(384, 384)
self.dropout = nn.Dropout(0.25)
self.linear3 = nn.Linear(384, 48)
self.r = nn.GELU()

@property
def required_features(self):
return list(META) + [COMPUTED.SOLAR_ANGLES] + self.nonhrv_channels + self.weather_channels

def forward(self, pv, features):
if self.nonhrv_channels:
feat1 = torch.concat([self.nonhrv_backbones[i](features[key]) for i, key in enumerate(self.nonhrv_channels)], dim=-1)
feat1 = torch.concat([self.nonhrv_backbones[i](features[key][:, 1::2]) for i, key in enumerate(self.nonhrv_channels)], dim=-1)
else:
feat1 = torch.Tensor([]).to("cuda")

Expand All @@ -140,6 +141,7 @@ def forward(self, pv, features):
all_feat = torch.concat([feat1, feat2, feat3], dim=-1)

x = self.r(self.linear1(all_feat))
x = self.dropout(x)
x = self.r(self.linear2(x))
x = torch.sigmoid(self.linear3(x))

Expand Down
11 changes: 10 additions & 1 deletion submission/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,16 @@ def predict(self, features: h5py.File):
# site_features = util.site_normalize(torch.from_numpy(site_features).to(device))
input_data = util.dict_to_device(input_data, device)

yield self.model(pv, input_data).cpu()
predictions0 = self.model(pv, input_data)

input_data[NONHRV.VIS008] = input_data[NONHRV.VIS008].flip(-1)

predictions1 = self.model(pv, input_data)

predictions = (predictions0 + predictions1) / 2

# yield self.model(pv, input_data).cpu()
yield predictions.cpu()


if __name__ == "__main__":
Expand Down