-
Notifications
You must be signed in to change notification settings - Fork 664
How to Fine-tuning pre-trained model with my own data? #116
Comments
You don't need a custom dataset. Organize your data so that the files look like:
Then run with |
If I retrain the model with 3 classes (tuna,other fish,other), can I use classify.lua to predict an image? |
you don't have to modify anything in the classification code, except editing this line to refer to your label names. |
I have a question is that if I retrain the model(fine-tuning) with my data, the model will only have my data or still have imagenet data? |
fine-tuning means that you start with the learned features on the imagenet dataset and adjust these features and maybe the structure of the model to suit your dataset/task instead of starting the learning process on your data from scratch with random weight initialisation. |
So if I want to build a fish classifer(only tuna,shark,dolphin,swordfish) with resnet structure, does it work? Can I use the code here to build my classifer? |
It doesn't make sense to have a solution with 1004 classes while you want only to classify between 4 classes. You can simply load a pre-trained ResNet model, remove the last classification layer and add a new layer with 4 classes only, and fine-tune the whole model, this will train your new layer and adjust the weights of the previously learned layers. Actually, I became curious to give this a try using the code in this repository and it worked well with me. Here are the steps:
Notes: I have tried with just 3 classes, you have to decrease the learning rate because you are not training from scratch, play with this value. for classify.lua,
3- as you have less than 5 classes: set N to your number of classes
and done 👍 |
Yes, you said the key point. I want to classify between 4 classes. So will this resnet code here achieve my purposes? How can I start it? Would you tell me the steps in detail? By the way I hope use torch to do this. |
@Laodax just updated my answer with the steps to use the code in this repository. |
Oh I really thank you!! I will try it again. Thanks a lot! |
Hi, |
@masaff, you'll need to convert your .mat files to .JPEG images. (See https://github.com/facebook/fb.resnet.torch/tree/master/pretrained#fine-tuning-on-a-custom-dataset) It depends on your data, but you'll likely get better accuracy if you fine-tune an existing model |
@colesbury Thanks for your reply. |
@colesbury @aabobakr Thanks for the reply, and I can also fine-tuning the pre-trained model with my own data set now following the instructions. |
My dataset has 2M images. It's a big dataset but the images( .mat files which have been saved as .jpg files) are kind of weird images. They are grey scale images which are very different than images in imagenet,flickers,.... . Basically there is no clear object or background or scene in them. I'm wondering if I should train a CNN from scratch or I can do fine-tuning on some pre-trained model and If yes which model should I go with? I'm totally new to deep learning sorry if my question is an obvious question:D |
@masaff: try both and see what works best. There's probably less benefit from starting with a pre-trained model if you have lots of data and your images are very different from the ImageNet training set. |
I tried to train with cifar10 and got the model_best.t7 with resnet-44. Now when I do classify.lua with the test images of cifar10 one by one, it always predicting cat. I have made the following changes in classify.lua(changed the imagenetLabel to use cifar10 label file that i created and also changed the mean(std) and transform in the classify.lua according to the mean(std) used in cifar10 in /datasets/cifar10.lua) Can someone help me please from the authors |
hi, |
What would be the sequence of the classes in imagenet.lua ? Should it be in alphabetical order or any specific |
I've organized my data in following manner in order to fine tuning ResNet50 using VMMRdb. In order to get started I'm just trying to retain the pretrained model with 8 classes of different car's models train//img1.jpg val//img4.jpg |
I have downloaded the pre-trained model resnet-200 and want to fine-tuning it. I look "Fine-tuning on a custom dataset" but I still don't know how to start. If I want to use my data(4 classes and each class has 100 image for example), I need to creat my custom data loader or datasets? I have seen "datasets readme" too, but I still have no idea...
Would you explain it clearly? Thank you very much.
The text was updated successfully, but these errors were encountered: