From 6082810a1b995dcd9ef30f479509bce1b8108f2a Mon Sep 17 00:00:00 2001 From: Val Rotan Date: Thu, 7 Mar 2024 05:14:01 +0000 Subject: [PATCH 1/2] 2yrs --- configs/mainmodel2.yaml | 4 ++-- submission/models/models.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/configs/mainmodel2.yaml b/configs/mainmodel2.yaml index 7806dd2..2ded6fd 100644 --- a/configs/mainmodel2.yaml +++ b/configs/mainmodel2.yaml @@ -1,7 +1,7 @@ model: name: mainmodel2 config: - meta_head: true + meta_head: false nonhrv_channels: # - IR_016 - VIS008 @@ -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 diff --git a/submission/models/models.py b/submission/models/models.py index 045171e..0c1742d 100644 --- a/submission/models/models.py +++ b/submission/models/models.py @@ -87,7 +87,7 @@ 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.fc = nn.Identity() @@ -99,13 +99,13 @@ 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) From 9f1ef70832d1546b99bdf10a34815eb2c71442eb Mon Sep 17 00:00:00 2001 From: Val Rotan Date: Thu, 7 Mar 2024 05:47:24 +0000 Subject: [PATCH 2/2] bias, aug, 6 channel, mirror --- data/random_data.py | 4 ++-- main.py | 9 ++++++++- submission/models/models.py | 14 ++++++++------ submission/run.py | 11 ++++++++++- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/data/random_data.py b/data/random_data.py index 05d368c..fb61403 100644 --- a/data/random_data.py +++ b/data/random_data.py @@ -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)), diff --git a/main.py b/main.py index 6f9b3a1..1158d61 100644 --- a/main.py +++ b/main.py @@ -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() diff --git a/submission/models/models.py b/submission/models/models.py index 0c1742d..6d570ad 100644 --- a/submission/models/models.py +++ b/submission/models/models.py @@ -89,7 +89,7 @@ def __init__(self, config) -> None: 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))]) @@ -108,11 +108,12 @@ def __init__(self, config) -> None: 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): @@ -120,7 +121,7 @@ def required_features(self): 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") @@ -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)) diff --git a/submission/run.py b/submission/run.py index 04c00c7..804cc2c 100644 --- a/submission/run.py +++ b/submission/run.py @@ -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__":