Image embedder finetuning example
See original GitHub issueHello i try to reproduce the finetuning image embedder example https://lightning-flash.readthedocs.io/en/latest/reference/image_embedder.html#finetuning
import flash
from flash import download_data
from flash.vision import ImageClassificationData, ImageEmbedder
# 1. Download the data
download_data("https://pl-flash-data.s3.amazonaws.com/hymenoptera_data.zip", "data/")
# 2. Load the data
datamodule = ImageClassificationData.from_folders(
train_folder="data/hymenoptera_data/train/",
valid_folder="data/hymenoptera_data/val/",
test_folder="data/hymenoptera_data/test/",
)
# 3. Build the model
embedder = ImageEmbedder(backbone="resnet18", embedding_dim=128)
# 4. Create the trainer. Run once on data
trainer = flash.Trainer(max_epochs=1)
# 5. Train the model
trainer.finetune(embedder, datamodule=datamodule, strategy="freeze_unfreeze")
# 6. Test the model
trainer.test()
# 7. Save it!
trainer.save_checkpoint("image_embedder_model.pt")
After that i use the saved checkpoint :
model = ImageEmbedder.load_from_checkpoint("image_embedder_model.pt")
model.predict("data/hymenoptera_data/predict/")
But the result is a class predictions instead of a list of vectors : [[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]]
lightning-flash 0.2.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Fine-Tune ViT for Image Classification with 🤗 Transformers
This paper explored how you can tokenize images, just as you would tokenize sentences, so that they can be passed to transformer models...
Read more >Fine tuning model using Triplet loss for Image search
Learn how to fine tune a model to compute image similarity using Triplet loss.
Read more >Transfer learning and fine-tuning | TensorFlow Core
When you don't have a large image dataset, it's a good practice to artificially introduce sample diversity by applying random, yet realistic, transformations...
Read more >How to Fine-tune Stable Diffusion using Textual Inversion
This tutorial focuses on how to fine-tune the embedding to create personalized images based on custom styles or objects. Instead of re-training the...
Read more >Fine-tuning with Keras and Deep Learning
In this tutorial, you will learn how to perform fine-tuning using Keras and Deep Learning for image classification.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I have changed the backbone to swav-imagenet and the embeddings are much better for my use case. Im closing the issue.
@psardin image embeddings can be trained in many ways. In this example it’s shown how to train them based on an image classification loss - that’s the reason of using
ImageClassificationDataand why the return value as the one hot encoding of the predicted classes. As @aniketmaurya suggested, if you could be more specific about your application we could suggest an alternative.