I have a project with Fashion MNIST, which predicts clothes from uploaded images, and I want to make some improvements with it. Is it possible to modify my project that it will train automatically after each uploaded and prediction?
You can train your model manually by using the transfer learning technique(Transfer learning is a method of reusing an already trained model for another task).
Instantiate a base model and load pre-trained weights into it.
Freeze all layers in the base model by setting trainable = False.
Create a new model on top of the output of one (or several) layers
from the base model. Train your new model on your new dataset.
Please refer to this gist for working code example. Thank You.
Related
I have trained a pretrained ResNet18 model with my custom dataset on Pytorch and wondered whether I could transfer my model file to train another one with a different architecture, e.g. ResNet50. I know I have to save my model accordingly (explained well on another post here) but this was a question that I have never thought before.
I was planning to use more advanced models like VisionTransformers (ViT) but I couldn't figure out whether I had to start with a pretrained ViT already or I could just take my previous model file and use it as the pretrained model to train a ViT.
Example Scenario: ResNet18 --> ResNet50 --> Inception v3 --> ViT
My best guess it that it's not possible due to number of weights, neurons and layer structures but I would love to hear that if I miss a crucial point here. Thanks!
Between models that only differ in number of layers (Resnet-18 and Resnet-50), it has been done to initialize some layers of the larger model from the weights of the smaller model's layers. Inversely, you can truncate a larger model by taking a subset of regularly spaced layers and initialize a smaller model. In both cases, you need to retrain everything at the end if you hope to achieve semi-decent performances.
The whole point of using architectures that vastly differ (vision transformers vs CNNs) is to learn different features from the inputs and unlock new levels of semantic understanding. Recent models like BeiT also use new self-supervised training schemes that have nothing to do with the classic ImageNet pretraining. Using trained weights from another model would go against the point.
Having said that,if you want to use a ViT, why not start from the available pretrained weights on HuggingFace and fine-tune it on the data you used to train your ResNet50 ?
I am just learning image classification with TensorFlow and found that there is a TensorFlow hub where we can use a lot of models for a lot of classification tasks. For example, I want to build food classification and develop the model so the model would cover foods in my country and have a higher accuracy on some specific foods. I try to use and tune this model: https://tfhub.dev/google/aiy/vision/classifier/food_V1/1, but why there is information that the model is not fine-tunable?
What makes a model can be fine-tuned and can't be fine-tuned?
Thank you.
The publisher/creator of the model makes he decision on whether the model is fine-tunable or not. Making a model fine-tunable requires model creator to make sure that the TF computation graph supports fine-tuning. For example, if the model contains dropout or batchnorm, the computation graph for fine-tuning and for inference-only will be different. The publisher/creator of the model has to make sure that model is exported correctly to support both these cases. Sometimes publishers do not to go through these steps and mark the model as non fine-tunable.
I trained a computer vision model in google colab.
Now I want to get it to my computer to work with it.
If I do model.save("name.h5") and then download the .h5 file, does this save the trained model?
Or is it just the untrained structure of the model?
Yes, model.save("name.h5") saves the trained model. Of course, you should execute this line after you have trained/fit the model.
However, model.save() only saves the model structure and the updated weights. And it does not store any loss function weights and information of the loss function. Therefore, you should avoid re-training your model after loading it from the saved file.
If you are willing to further re-train your model, you should use tf.keras.models.save_model() to save a model, and tf.keras.models.load_model() to load a model. Further information can be found in the Keras documentation.
I have a tensorflow model which I trained using object detection SSD mobile net .
The training is finished now and I exported the model inference for testing .My inquiry is if I want to retrain the model later with new dataset of images, what should i do now at the stage to make the weights permeant in the model so that I can retrain it from that point on .I know there is a freeze script ,do I have to use that ?
Thanks
Ayad
You cannot retrain it from that point on. Every time you retrain it should be for all objects that you are interested in.
I have a trained model with 10 classes and i need to add new class without loosing the weights of the pre-trained. I know that in order to do this issue, I should first of all load the pre-trained, remove/replace the FC , freeze lower layers of the pre-trained model and train the network. So theoritical is clear but practically which method i should call for loading the previous trained model because i have confused between just restore the last checkpoint saver.restore(sess, tf.train.latest_checkpoint) or by importing meta graph by calling tf.train.import_meta_graph .
According to freeze all the weights, i don't know which methods are responsible for that ? Any idea or if there any other possible way to add new class.