0
$\begingroup$

I have been trying out various tutorials on object detection machine learning. All the tutorials so far have been to use a pre-trained model for practical reasons when detecting objects that the pre-trained model learnt (e.g cats & dogs). However, will this pre-trained model work if I input a few hundred images of a particular car engine part and predict this class, which the pre-trained model did not train on? Is it recommended to make a model from scratch in this case?

I am further confused by this in TensorFlow documentation (Images -> Transfer learning and fine-tuning), the summary states:

Using a pre-trained model for feature extraction: When working with a small dataset, it is a common practice to take advantage of features learned by a model trained on a larger dataset in the same domain

By that meaning, if I need to predict a particular car engine part then this statement seems to suggest I create a model from scratch?

TLDR: Will pre-trained model be able to work on image dataset that it has never learn before or better to work on a model from scratch?

$\endgroup$
1

2 Answers 2

2
$\begingroup$

Well, I think you forget about "fine tuning" stage here. What they mean in these tutorials is that you take such model that was pretrained on large dataset and you usually freeze from training all layers except the last one or few last ones and you train these last layer/layers on your smaller specific dataset. This is called "transfer learning".

So in theory model should learn more general features during that first trainin and use them without changes in the second training (fine tuning), when it learns features more specific to your problem. Only then you can use it for detection objects from your dataset. If the model has never seen a labeled part from your dataset during its training it will never come up what this is by itself that's why you need this fine tuning process. But fortunately it requires far less data and thanks to that is much faster too.

Usually you let fine tune only last layer. But if you feel that your problem is noticeably different from the images the model been trained on then you can try tuning two or three last layers.

It's not alaways easy to find a model pretrained on dataset from every possible domain so usually you just start with a model pretrained on datasets containing images of very general classes of objects such as ImageNet or COCO.

If you work on a model from scratch it would probably require a lot of data. It's easy to overfit deep learning models with just few hundreds samples.

$\endgroup$
3
  • $\begingroup$ Thanks for your reply. I tried to find information regarding freezing the last layer you mentioned but TensorFlow objection detection API does not seem to have these layers in the pipeline.config (I am using Tensorflow 2 Model Zoo). Do you have a website which clearly show this? I see there are example in Keras but I am not using Keras. $\endgroup$
    – SunnyBoiz
    Aug 26, 2022 at 5:39
  • $\begingroup$ You don't freeze the last one but all previous ones except last one. I haven't used this object detection API for a long time but I am pretty sure these weights are already freezed by default. I followed these tutorials and it was working for me all fine: youtu.be/yqkISICHH-U and youtube.com/playlist?list=PLQVvvaa0QuDcNK5GeCQnxYnSSaar2tpku $\endgroup$
    – GKozinski
    Aug 26, 2022 at 8:19
  • $\begingroup$ @SunnyBoiz Also if your goal is to make a good object detection model and you dont care what models you use I would recommend Ultralytic's implementation of YOLOv5 instead of Tensorflow object detection API. Much smoother and easier to setup and better results. $\endgroup$
    – GKozinski
    Aug 26, 2022 at 8:23
0
$\begingroup$

Besides the answer from @GKozinski, you can also fine tune all the layers of the pretrained model.

Yes, it is incredibly commonplace to do transfer learning using pretrained models from different domains.

$\endgroup$
2
  • $\begingroup$ Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. $\endgroup$
    – Community Bot
    Aug 29, 2022 at 3:06
  • $\begingroup$ Could you provide more reading articles on fine tuning all the layers? In object detection API of TensorFlow, I do not really see any layers. $\endgroup$
    – SunnyBoiz
    Aug 29, 2022 at 14:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .