anh1811 commited on
Commit
f9383a8
·
1 Parent(s): af0d38a

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +42 -42
model.py CHANGED
@@ -4,7 +4,7 @@ Implementation of YOLOv3 architecture
4
 
5
  import torch
6
  import torch.nn as nn
7
- import config as cfg
8
  """
9
  Information about architecture config:
10
  Tuple is structured by (filters, kernel_size, stride)
@@ -107,8 +107,8 @@ class YOLOv3(nn.Module):
107
  self.in_channels = in_channels
108
  self.layers = self._create_conv_layers()
109
  self.base_model = None
110
- self.distill_feature = cfg.DISTILL
111
- self.warp = cfg.WARP
112
  self.feature_store = None
113
  self.enable_warp_train = False
114
 
@@ -198,42 +198,42 @@ class YOLOv3(nn.Module):
198
 
199
 
200
 
201
- if __name__ == "__main__":
202
- num_classes = 19
203
- IMAGE_SIZE = 416
204
- model = YOLOv3(num_classes=num_classes)
205
- # print(model)
206
- print(model.layers[15].pred[1].conv.weight.shape)
207
- print(model.layers[15].pred[1].conv.bias.shape)
208
- import torch.optim as optim
209
- optimizer = optim.Adam(
210
- model.parameters(), lr=cfg.LEARNING_RATE, weight_decay=cfg.WEIGHT_DECAY
211
- )
212
- from utils import load_checkpoint
213
- load_checkpoint(
214
- cfg.BASE_CHECK_POINT, model, optimizer, cfg.LEARNING_RATE
215
- )
216
-
217
- model.adaptation(layer_id = 15, num_class = 20, in_feature = 1024, old_class = num_classes)
218
- model.adaptation(layer_id = 22, num_class = 20, in_feature = 512, old_class = num_classes)
219
- model.adaptation(layer_id = 29, num_class = 20, in_feature = 256, old_class = num_classes)
220
- # layer1 =
221
- # model.eval()
222
- # with torch.no_grad():
223
- # old_weight = model.layers[15].pred[1].conv.weight
224
- # old_bias = model.layers[15].pred[1].conv.bias
225
- # # print(model.layers[22].pred[1])
226
- # # print(model.layers[29].pred[1])
227
- # # out_dims = cfg.BASE_CLASS + cfg.NEW_CLASS + 5
228
- # model.layers[15].pred[1] = CNNBlock(1024, 25 * 3, bn_act=False, kernel_size=1)
229
- # model.layers[15].pred[1].conv.weight[:72] = old_weight
230
- # model.layers[15].pred[1].conv.bias[:72] = old_bias
231
- print(model.layers[15].pred[1].conv.weight.shape)
232
- # model.layers[22].pred[1] = CNNBlock(512, out_dims * 3, kernel_size=1)
233
- # model.layers[29].pred[1] = CNNBlock(256, out_dims * 3, kernel_size=1)
234
- x = torch.randn((2, 3, IMAGE_SIZE, IMAGE_SIZE))
235
- out = model(x)
236
- # assert model(x)[0].shape == (2, 3, IMAGE_SIZE//32, IMAGE_SIZE//32, num_classes + 5)
237
- # assert model(x)[1].shape == (2, 3, IMAGE_SIZE//16, IMAGE_SIZE//16, num_classes + 5)
238
- # assert model(x)[2].shape == (2, 3, IMAGE_SIZE//8, IMAGE_SIZE//8, num_classes + 5)
239
- print("Success!")
 
4
 
5
  import torch
6
  import torch.nn as nn
7
+ # import config as cfg
8
  """
9
  Information about architecture config:
10
  Tuple is structured by (filters, kernel_size, stride)
 
107
  self.in_channels = in_channels
108
  self.layers = self._create_conv_layers()
109
  self.base_model = None
110
+ # self.distill_feature = cfg.DISTILL
111
+ # self.warp = cfg.WARP
112
  self.feature_store = None
113
  self.enable_warp_train = False
114
 
 
198
 
199
 
200
 
201
+ # if __name__ == "__main__":
202
+ # num_classes = 19
203
+ # IMAGE_SIZE = 416
204
+ # model = YOLOv3(num_classes=num_classes)
205
+ # # print(model)
206
+ # print(model.layers[15].pred[1].conv.weight.shape)
207
+ # print(model.layers[15].pred[1].conv.bias.shape)
208
+ # import torch.optim as optim
209
+ # optimizer = optim.Adam(
210
+ # model.parameters(), lr=cfg.LEARNING_RATE, weight_decay=cfg.WEIGHT_DECAY
211
+ # )
212
+ # from utils import load_checkpoint
213
+ # load_checkpoint(
214
+ # cfg.BASE_CHECK_POINT, model, optimizer, cfg.LEARNING_RATE
215
+ # )
216
+
217
+ # model.adaptation(layer_id = 15, num_class = 20, in_feature = 1024, old_class = num_classes)
218
+ # model.adaptation(layer_id = 22, num_class = 20, in_feature = 512, old_class = num_classes)
219
+ # model.adaptation(layer_id = 29, num_class = 20, in_feature = 256, old_class = num_classes)
220
+ # # layer1 =
221
+ # # model.eval()
222
+ # # with torch.no_grad():
223
+ # # old_weight = model.layers[15].pred[1].conv.weight
224
+ # # old_bias = model.layers[15].pred[1].conv.bias
225
+ # # # print(model.layers[22].pred[1])
226
+ # # # print(model.layers[29].pred[1])
227
+ # # # out_dims = cfg.BASE_CLASS + cfg.NEW_CLASS + 5
228
+ # # model.layers[15].pred[1] = CNNBlock(1024, 25 * 3, bn_act=False, kernel_size=1)
229
+ # # model.layers[15].pred[1].conv.weight[:72] = old_weight
230
+ # # model.layers[15].pred[1].conv.bias[:72] = old_bias
231
+ # print(model.layers[15].pred[1].conv.weight.shape)
232
+ # # model.layers[22].pred[1] = CNNBlock(512, out_dims * 3, kernel_size=1)
233
+ # # model.layers[29].pred[1] = CNNBlock(256, out_dims * 3, kernel_size=1)
234
+ # x = torch.randn((2, 3, IMAGE_SIZE, IMAGE_SIZE))
235
+ # out = model(x)
236
+ # # assert model(x)[0].shape == (2, 3, IMAGE_SIZE//32, IMAGE_SIZE//32, num_classes + 5)
237
+ # # assert model(x)[1].shape == (2, 3, IMAGE_SIZE//16, IMAGE_SIZE//16, num_classes + 5)
238
+ # # assert model(x)[2].shape == (2, 3, IMAGE_SIZE//8, IMAGE_SIZE//8, num_classes + 5)
239
+ # print("Success!")