ml-cvnets
ml-cvnets copied to clipboard
How to load MobileViT for my project
Hi!
I want to use MobileViT and train it using my own dataset (on Google Colab). I couldn't understand how can I use the code in this repository to instantiate just MobileViT model, and use it (I have a very specific data augmentation functions to use).
I am looking for a code to do something like this:
import cvnets.models.classification import MobileViT
import torch
model = MobileViT()
model.load_state_dict(torch.load(PATH))
# Train ...
How can I do that with the original implementation of MobileViT ?
Their code of creating model is kind of messy, but I trace their code and found a way to somewhat get rid of it. First, suggest we have the weight.pt and config.yaml of a model from model_zoo then we can
import torch
from options.opts import get_training_arguments
from cvnets import get_model
def save_model(*args, **kwargs):
opts = get_training_arguments()
model = get_model(opts)
torch.save(model, 'model_structure.pt')
if __name__ == "__main__":
save_model()
python .\save_model.py --common.config-file config.yaml
to get the whole specific model structure saved in pt file.
From now on, we can do whatever we want without a lot of unnecessary dependency / information.
import torch
model = torch.load('model_structure.pt')
model.load_state_dict(torch.load('weight.pt'))
# Train ...
Little suggestion to the dev team, some sample code of how to inference your model that list in model_zoo using a single sample picture in 'simple python code' (not some prebuilt executable) will be helpful, like any other modern github model release will do. (https://github.com/openai/CLIP FYI)
how do i use ml-cvnet?
when i use follow command
export CFG_FILE="config/classification/imagenet/resnet.yaml" cvnets-train --common.config-file $CFG_FILE --common.results-loc classification_results
main_train: Command not found
how do i use ml-cvnet? when i use follow command
export CFG_FILE="config/classification/imagenet/resnet.yaml" cvnets-train --common.config-file $CFG_FILE --common.results-loc classification_results
main_train: Command not found
I also have this question,are you have a solution?
Their code of creating model is kind of messy, but I trace their code and found a way to somewhat get rid of it. First, suggest we have the weight.pt and config.yaml of a model from model_zoo then we can
import torch from options.opts import get_training_arguments from cvnets import get_model def save_model(*args, **kwargs): opts = get_training_arguments() model = get_model(opts) torch.save(model, 'model_structure.pt') if __name__ == "__main__": save_model()
python .\save_model.py --common.config-file config.yaml
to get the whole specific model structure saved in pt file.
From now on, we can do whatever we want without a lot of unnecessary dependency / information.
import torch model = torch.load('model_structure.pt') model.load_state_dict(torch.load('weight.pt')) # Train ...
Little suggestion to the dev team, some sample code of how to inference your model that list in model_zoo using a single sample picture in 'simple python code' (not some prebuilt executable) will be helpful, like any other modern github model release will do. (https://github.com/openai/CLIP FYI)
I want to fine tune the Mobilevit model for my dataset (only classification model needed). So, I need to download the Mobilevit xxs version, with Imagenet pretrained weights. I have implemented the Read me instructions. I have issues downloading the classification Mobilevit model. Could you please guide me?