From a97f350461287daaabaac3200d90b7eec440453f Mon Sep 17 00:00:00 2001 From: Oulbacha Reda Date: Mon, 22 Jun 2020 16:15:40 -0400 Subject: [PATCH 1/5] Non-output layer freeze in train.py (#1333) Freeze layers that aren't of type YOLOLayer and that aren't the conv layers preceeding them --- train.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/train.py b/train.py index ca99daca..5abcacf0 100644 --- a/train.py +++ b/train.py @@ -143,6 +143,16 @@ def train(hyp): elif len(weights) > 0: # darknet format # possible weights are '*.weights', 'yolov3-tiny.conv.15', 'darknet53.conv.74' etc. load_darknet_weights(model, weights) + + if opt.freeze_layers: + output_layer_indices = [idx - 1 for idx, module in enumerate(model.module_list) \ + if isinstance(module, YOLOLayer)] + freeze_layer_indices = [x for x in range(len(model.module_list)) if\ + (x not in output_layer_indices) and \ + (x - 1 not in output_layer_indices)] + for idx in freeze_layer_indices: + for parameter in model.module_list[idx].parameters(): + parameter.requires_grad_(False) # Mixed precision training https://github.com/NVIDIA/apex if mixed_precision: @@ -394,6 +404,7 @@ if __name__ == '__main__': parser.add_argument('--device', default='', help='device id (i.e. 0 or 0,1 or cpu)') parser.add_argument('--adam', action='store_true', help='use adam optimizer') parser.add_argument('--single-cls', action='store_true', help='train as single-class dataset') + parser.add_argument('--freeze-layers', action='store_true', help='Freeze non-output layers') opt = parser.parse_args() opt.weights = last if opt.resume else opt.weights check_git_status() From e276e3a1030a672fab6135c90a42f8b454713dc1 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 22 Jun 2020 15:20:08 -0700 Subject: [PATCH 2/5] Update greetings.yml --- .github/workflows/greetings.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml index 2c5c5c70..860c4a26 100644 --- a/.github/workflows/greetings.yml +++ b/.github/workflows/greetings.yml @@ -16,7 +16,7 @@ jobs: - + To continue with this repo, please visit our [Custom Training Tutorial](https://github.com/ultralytics/yolov3/wiki/Train-Custom-Data) to get started, and see our [Google Colab Notebook](https://github.com/ultralytics/yolov3/blob/master/tutorial.ipynb), [Docker Image](https://hub.docker.com/r/ultralytics/yolov3), and [GCP Quickstart Guide](https://github.com/ultralytics/yolov3/wiki/GCP-Quickstart) for example environments. @@ -27,4 +27,4 @@ jobs: - **Edge AI** integrated into custom iOS and Android apps for realtime **30 FPS video inference.** - **Custom data training**, hyperparameter evolution, and model exportation to any destination. - For more information please visit https://www.ultralytics.com. \ No newline at end of file + For more information please visit https://www.ultralytics.com. From 8a414743e2fd92d2bc471c1f92281f82cf31bc10 Mon Sep 17 00:00:00 2001 From: Chang Lee Date: Mon, 22 Jun 2020 22:07:51 -0400 Subject: [PATCH 3/5] Fixed string format error during weight conversion (#1334) --- models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models.py b/models.py index 0323b25e..d5cfc02a 100755 --- a/models.py +++ b/models.py @@ -438,7 +438,7 @@ def convert(cfg='cfg/yolov3-spp.cfg', weights='weights/yolov3-spp.weights'): target = weights.rsplit('.', 1)[0] + '.pt' torch.save(chkpt, target) - print("Success: converted '%s' to 's%'" % (weights, target)) + print("Success: converted '%s' to '%s'" % (weights, target)) else: print('Error: extension not supported.') From a587d39cd447b85219e761734b5f1d5cb30197d8 Mon Sep 17 00:00:00 2001 From: NanoCode012 Date: Thu, 25 Jun 2020 01:37:09 +0700 Subject: [PATCH 4/5] Fixed train.py SyntaxError due to last commit (#1336) Fixed unexpected character after line continuation character on line 148,150, and 151 --- train.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/train.py b/train.py index 5abcacf0..705b5198 100644 --- a/train.py +++ b/train.py @@ -145,10 +145,9 @@ def train(hyp): load_darknet_weights(model, weights) if opt.freeze_layers: - output_layer_indices = [idx - 1 for idx, module in enumerate(model.module_list) \ - if isinstance(module, YOLOLayer)] - freeze_layer_indices = [x for x in range(len(model.module_list)) if\ - (x not in output_layer_indices) and \ + output_layer_indices = [idx - 1 for idx, module in enumerate(model.module_list) if isinstance(module, YOLOLayer)] + freeze_layer_indices = [x for x in range(len(model.module_list)) if + (x not in output_layer_indices) and (x - 1 not in output_layer_indices)] for idx in freeze_layer_indices: for parameter in model.module_list[idx].parameters(): From e1fb453079eea03f4da2b572abeab6d4dced9900 Mon Sep 17 00:00:00 2001 From: Jason Nataprawira <52592216+jas-nat@users.noreply.github.com> Date: Thu, 25 Jun 2020 20:09:41 +0700 Subject: [PATCH 5/5] Update requirements.txt (#1339) Add torchvision --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 08c696bb..7b631ebe 100755 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ numpy == 1.17 opencv-python >= 4.1 torch >= 1.5 +torchvision matplotlib pycocotools tqdm