yjh0410 1 жил өмнө
parent
commit
c5b2c0e3ab

+ 0 - 37
models/yolov3/yolov3_backbone.py

@@ -6,14 +6,6 @@ try:
 except:
     from  yolov3_basic import BasicConv, ResBlock
 
-# IN1K pretrained weight
-pretrained_urls = {
-    's': None,
-    'm': None,
-    'l': None,
-    'x': None,
-}
-
 
 # --------------------- Yolov3's Backbone -----------------------
 ## Modified DarkNet
@@ -93,10 +85,6 @@ class Yolov3Backbone(nn.Module):
         # Initialize all layers
         self.init_weights()
         
-        # Load imagenet pretrained weight
-        if cfg.use_pretrained:
-            self.load_pretrained()
-
     def init_weights(self):
         """Initialize the parameters."""
         for m in self.modules():
@@ -105,31 +93,6 @@ class Yolov3Backbone(nn.Module):
                 # reset the Conv2d initialization parameters
                 m.reset_parameters()
 
-    def load_pretrained(self):
-        url = pretrained_urls[self.model_scale]
-        if url is not None:
-            print('Loading backbone pretrained weight from : {}'.format(url))
-            # checkpoint state dict
-            checkpoint = torch.hub.load_state_dict_from_url(
-                url=url, map_location="cpu", check_hash=True)
-            checkpoint_state_dict = checkpoint.pop("model")
-            # model state dict
-            model_state_dict = self.state_dict()
-            # check
-            for k in list(checkpoint_state_dict.keys()):
-                if k in model_state_dict:
-                    shape_model = tuple(model_state_dict[k].shape)
-                    shape_checkpoint = tuple(checkpoint_state_dict[k].shape)
-                    if shape_model != shape_checkpoint:
-                        checkpoint_state_dict.pop(k)
-                else:
-                    checkpoint_state_dict.pop(k)
-                    print('Unused key: ', k)
-            # load the weight
-            self.load_state_dict(checkpoint_state_dict)
-        else:
-            print('No pretrained weight for model scale: {}.'.format(self.model_scale))
-
     def forward(self, x):
         c1 = self.layer_1(x)
         c2 = self.layer_2(c1)

+ 0 - 37
models/yolov4/yolov4_backbone.py

@@ -6,14 +6,6 @@ try:
 except:
     from  yolov4_basic import BasicConv, CSPBlock
 
-# IN1K pretrained weight
-pretrained_urls = {
-    's': None,
-    'm': None,
-    'l': None,
-    'x': None,
-}
-
 
 # --------------------- Yolov3's Backbone -----------------------
 ## Modified DarkNet
@@ -93,10 +85,6 @@ class Yolov4Backbone(nn.Module):
         # Initialize all layers
         self.init_weights()
         
-        # Load imagenet pretrained weight
-        if cfg.use_pretrained:
-            self.load_pretrained()
-
     def init_weights(self):
         """Initialize the parameters."""
         for m in self.modules():
@@ -105,31 +93,6 @@ class Yolov4Backbone(nn.Module):
                 # reset the Conv2d initialization parameters
                 m.reset_parameters()
 
-    def load_pretrained(self):
-        url = pretrained_urls[self.model_scale]
-        if url is not None:
-            print('Loading backbone pretrained weight from : {}'.format(url))
-            # checkpoint state dict
-            checkpoint = torch.hub.load_state_dict_from_url(
-                url=url, map_location="cpu", check_hash=True)
-            checkpoint_state_dict = checkpoint.pop("model")
-            # model state dict
-            model_state_dict = self.state_dict()
-            # check
-            for k in list(checkpoint_state_dict.keys()):
-                if k in model_state_dict:
-                    shape_model = tuple(model_state_dict[k].shape)
-                    shape_checkpoint = tuple(checkpoint_state_dict[k].shape)
-                    if shape_model != shape_checkpoint:
-                        checkpoint_state_dict.pop(k)
-                else:
-                    checkpoint_state_dict.pop(k)
-                    print('Unused key: ', k)
-            # load the weight
-            self.load_state_dict(checkpoint_state_dict)
-        else:
-            print('No pretrained weight for model scale: {}.'.format(self.model_scale))
-
     def forward(self, x):
         c1 = self.layer_1(x)
         c2 = self.layer_2(c1)