How to Fine-Tune a Pretrained Model on Your Own Data
To fine-tune a pretrained model, you start from weights already trained on a large dataset (ImageNet for vision backbones, large text corpora for BERT-style transformers, COCO for YOLO), replace the output layer for your classes, and continue training on your labeled data with a small learning rate. On TensorTurn you describe this in chat and it generates and runs the fine-tuning notebook in PyTorch, Keras, Ultralytics YOLO or Hugging Face transformers on a cloud GPU or your own GPU. Fine-tuning usually beats training from scratch whenever your dataset is in the hundreds or low thousands of examples.
What fine-tuning actually does
A pretrained network has already learned general features: edges, textures and shapes for images, grammar and word meaning for text, objectness for detectors. Fine-tuning keeps those features and adapts them to your task. You swap the final layer (the 'head') for one with your number of classes, then train either just that head or the whole network for a few epochs. Because the model is not learning everything from zero, it needs far less data and compute, and it converges in minutes to hours instead of days.
Fine-tune or train from scratch?
| Situation | Better choice | Why |
|---|---|---|
| A few hundred to tens of thousands of labeled images or documents | Fine-tune | Pretrained features fill the gap your data cannot |
| Natural photos, everyday objects, general-domain text | Fine-tune | Close to what the backbone was pretrained on |
| Very different domain (radar, spectrograms, microscopy) with lots of data | Try both | Pretrained features transfer less well, but still often help as initialisation |
| Tabular data (rows and columns) | Train from scratch | Gradient boosting such as XGBoost or LightGBM usually wins; there is no general pretrained tabular backbone to fine-tune |
| Millions of labeled examples and a custom architecture | Train from scratch is viable | Enough data to learn features directly |
| Tight inference budget on small devices | Fine-tune a small model | Start from a compact pretrained model rather than shrinking a large one |
Which pretrained models to start from
- Image classification: ResNet-50 or EfficientNet for a dependable CNN, ViT or ConvNeXt when you have more data and GPU budget, MobileNet when the model has to be small. All are available with ImageNet weights in PyTorch and Keras.
- Object detection and segmentation: YOLO models from Ultralytics come pretrained on COCO and fine-tune well on custom boxes or masks. Pick a smaller variant (n or s) for speed and a larger one (m or l) for accuracy.
- Text: DistilBERT for a fast baseline, BERT or RoBERTa base for stronger accuracy, and multilingual variants when your text is not only English. These load through Hugging Face transformers inside the generated Python notebook.
- Embeddings: sentence-embedding models when you need similarity search or clustering rather than a classifier.
Fine-tuning strategies and learning rates
The learning rate is the setting that most often makes or breaks a fine-tune. Too high and you destroy the pretrained features in the first epoch, a failure known as catastrophic forgetting. Too low and the head never adapts. The table gives common starting points, not guarantees; tune from there.
| Strategy | What is trained | Typical learning rate | Use when |
|---|---|---|---|
| Feature extraction (linear probe) | Only the new head; backbone frozen | 1e-3 with Adam | Very small dataset, or a quick baseline |
| Partial fine-tune | Head plus the last few blocks | 1e-4 for unfrozen blocks, 1e-3 for the head | Moderate data, domain somewhat different |
| Full fine-tune (CNN or ViT) | All layers | 1e-4 to 1e-5 with Adam or AdamW | Enough data and a GPU |
| Full fine-tune (BERT-style) | All layers | 2e-5 to 5e-5 with AdamW, linear warmup | Text classification, NER, sentiment |
| YOLO fine-tune | Whole detector from COCO weights | Ultralytics defaults are a good start | Custom object detection |
Two habits help almost every fine-tune: a short warmup so early large gradients do not wreck the weights, and lower learning rates for earlier layers than for later ones (discriminative learning rates). Use early stopping on validation loss, because small datasets overfit quickly, often within 3 to 10 epochs.
How much data do you need?
There is no fixed number, but useful rules of thumb exist. For image classification, a few hundred well-labeled images per class usually gives a working model when fine-tuning, and accuracy keeps improving into the thousands. For YOLO, aim for a few hundred labeled instances per class with varied backgrounds, lighting and scale. For text classification, a few hundred examples per class is a reasonable start for a fine-tuned transformer. Balance matters as much as size: ten examples of a rare class will be learned poorly whatever the backbone.
Common fine-tuning mistakes
- Wrong preprocessing. Pretrained vision models expect the same input size and normalisation they were trained with, and text models need their own tokenizer.
- Learning rate copied from a from-scratch tutorial, which erases what the model already knew.
- No held-out test set, or near-duplicate images across train and test. Pretrained models memorise duplicates easily, so leakage inflates scores more than usual.
- Unfreezing everything on a tiny dataset. Start frozen, then unfreeze gradually if validation scores keep improving.
- Assuming bigger is better. A larger backbone on a small, noisy dataset often overfits; clean labels usually help more.
How to fine-tune a model on TensorTurn
- Upload your dataset: an image archive (zip, rar or 7z) for vision, or a CSV, JSON or Parquet file with text and label columns. You can also import by link from Hugging Face or Kaggle.
- For images, run the duplicate, blur, leakage and mislabel checks first and fix what they flag.
- Describe the fine-tune in chat, for example: 'Fine-tune an ImageNet-pretrained EfficientNet on these 5 classes, freeze the backbone for 2 epochs, then unfreeze with a lower learning rate' or 'Fine-tune DistilBERT on the review column to predict sentiment'.
- TensorTurn generates and runs the notebook on an isolated cloud GPU, or free on your own connected GPU. If a cell fails, it reads the traceback, patches that cell and retries.
- Compare the metrics it reports against a frozen-backbone baseline, then save the best weights, deploy a /predict API or export to ONNX.
TensorTurn does not offer a dedicated large language model fine-tuning product. Because every run is generated Python, standard libraries such as Hugging Face transformers can be used inside the notebook, but plan GPU memory accordingly for large models.
Frequently asked questions
What is the difference between fine-tuning and transfer learning?
Transfer learning is the general idea of reusing knowledge from one task on another. Fine-tuning is the most common way to do it: you continue training some or all of a pretrained model's layers on your own labeled data, usually with a small learning rate.
What learning rate should I use for fine-tuning?
Common starting points are 2e-5 to 5e-5 with AdamW for BERT-style transformers, 1e-4 to 1e-5 for fully fine-tuning a CNN or ViT, and around 1e-3 when only training a new head on a frozen backbone. Use warmup and early stopping, then tune from there.
Can I fine-tune YOLO on my own images?
Yes. Upload images with bounding-box labels, ask for a YOLO fine-tune in chat, and TensorTurn runs Ultralytics training starting from pretrained weights, then reports mAP. You can deploy the result as a /predict endpoint.
Can I fine-tune a large language model on TensorTurn?
There is no dedicated LLM fine-tuning feature. The notebooks are generated Python, so Hugging Face transformers can be used inside them, which suits BERT-style models well; very large models are limited by the GPU memory available to the run.
Should I freeze layers when fine-tuning?
With very little data, freeze the backbone and train only the head first. With more data, unfreeze the later layers or the whole model at a lower learning rate. Gradual unfreezing is a safe default when you are unsure.