question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EfficientDet pretrained arch transfer learning

See original GitHub issue

📓 New <Tutorial/Example>

Request for an example

What is the task? Object detection using transfer learning for the whole architecture. Are there some defined methods to load fastai model and change its head to a different number of classes, similar to this?

I was able to run the Faster-RCNN example using this example trained on COCO dataset and evaluate its mAP.

The EfficientDet workflow seems not to be yet ready. Has there been some update on that?

I was able to create EfficientDet with pretrained encoder and train it myself on COCO. I’m now trying to do transfer learning for a different number of classes. Loading model through fastai, expectedly, throws an error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-22-cf184f01fec3> in <module>
----> 1 learn.load('coco_local')

~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py in load(self, file, with_opt, device, **kwargs)
    293         if self.opt is None: self.create_opt()
    294         file = join_path_file(file, self.path/self.model_dir, ext='.pth')
--> 295         load_model(file, self.model, self.opt, device=device, **kwargs)
    296         return self
    297 

~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py in load_model(file, model, opt, with_opt, device, strict)
     47     hasopt = set(state)=={'model', 'opt'}
     48     model_state = state['model'] if hasopt else state
---> 49     get_model(model).load_state_dict(model_state, strict=strict)
     50     if hasopt and with_opt:
     51         try: opt.load_state_dict(state['opt'])

~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict)
   1049 
   1050         if len(error_msgs) > 0:
-> 1051             raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
   1052                                self.__class__.__name__, "\n\t".join(error_msgs)))
   1053         return _IncompatibleKeys(missing_keys, unexpected_keys)

RuntimeError: Error(s) in loading state_dict for DetBenchTrain:
	size mismatch for model.class_net.predict.conv_pw.weight: copying a param with shape torch.Size([819, 64, 1, 1]) from checkpoint, the shape in current model is torch.Size([99, 64, 1, 1]).
	size mismatch for model.class_net.predict.conv_pw.bias: copying a param with shape torch.Size([819]) from checkpoint, the shape in current model is torch.Size([99]).

Is this example for a specific model? EfficientDet

Is this example for a specific dataset? COCO transfer learning


Don’t remove Main issue for examples: #39

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
potipotcommented, Jan 29, 2021

COCOMetric gives correct results for validation with this change:

def build_valid_batch(records, batch_tfms=None):
    (images, targets), records = build_train_batch(
        records=records, batch_tfms=batch_tfms
    )

-   img_sizes = [(r["height"], r["width"]) for r in records]
-   targets["img_size"] = tensor(img_sizes, dtype=torch.float)
+   # passing the size of transformed image to efficientdet, necessary for its own scaling and resizing, see
+   # https://github.com/rwightman/efficientdet-pytorch/blob/645d84a6f0cd837703f98f48179a06c354902515/effdet/bench.py#L100
+   targets["img_size"] = tensor([image.shape[-2:] for image in images], dtype=torch.float)
    targets["img_scale"] = tensor([1] * len(records), dtype=torch.float)

    return (images, targets), records
1reaction
lgvazcommented, Jan 27, 2021

Amazing work @potipot, I was going to investigate this right now but you already solved it! hahahah

So, if I understood correctly, the error is on this line? Here we are setting the image size without padding, but instead we need to set the image size with padding? If so we just need to take the image size from the images tensor images.shape[2:]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Retraining EfficientDet for High-Accuracy Object Detection
Retraining EfficientDet for High-Accuracy Object Detection. A practical guide to fine-tuning EfficientDet for transfer learning on a custom ...
Read more >
TAO Pretrained EfficientDet - NVIDIA NGC
Transfer learning with pre-trained models can be used for AI applications in smart cities, retail, healthcare, industrial inspection and more.
Read more >
Training EfficientDet Object Detection Model with a Custom ...
We train from the EfficientNet base backbone, without using a pre-trained checkpoint for the detector portion of the network. We train for 20 ......
Read more >
EfficientDet: Scalable and Efficient Object ... - ResearchGate
For CC and AC we follow a conventional image classification transfer learning workflow where convolutional-based neural networks pre-trained ...
Read more >
Lesson 5 - EfficientNet and Custom Pretrained Models
Using a PyTorch model; Using pre-trained weights for transfer learning ... def create_body(arch, pretrained=True, cut=None): "Cut off the body of a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found