Memuat
Memuat
Watch every step above performed live, with English narration.
1 plays
Class book
Page 1 / 6
Cover: Leaf Disease Transfer Learning Class #3: Transfer Learning with MobileNetV2 & ResNet50: Feature Extraction
Click a page or use ◀ ▶ to turn · swipe on mobile · to enlarge
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Leaf Disease Transfer Learning Class #3: Transfer Learning with MobileNetV2 & ResNet50: Feature Extraction”.
Other ways we can help with Python.
Learn with a mentor
Scheduled AI & Machine Learning courses with live guidance and a certificate.

Multi-Objective Optimization Course: NSGA-II, MOPSO & Hybrid Algorithms (Python)

ECG Arrhythmia Classification Course with Wavelet & Deep Learning (PyTorch)

ANFIS + PSO/GA Course for Non-Linear Time Series Forecasting (Python)
Have it built for you
No time to learn Python? Our team can do the project for you.

Python Machine Learning — Prediction Models, Customer Segmentation, Fraud Detection & AI Apps

AI Image Creation with Stable Diffusion — Unlimited Custom Visual Production
★ 4.9

AI Image & Video Creation with Leonardo AI — All-in-One Visuals for Business
★ 4.9
Get notified about new Python classes
At most one email a week. Unfollow anytime with one click.
The full narration of this video. The current sentence is highlighted while the video plays; click any sentence to jump there.
Here is the final result, two huge models that have been trained with millions of ImageNet photos, MobileNet V2 and ResNet 50, we reuse them to recognize tomato leaf diseases by training less than 1% of their parameters. The graph compares the validation accuracy of both. Let's get started. Hello, welcome to episode three of the leaf disease detection series using transfer learning and hyperparameter optimization. Training a CNN from scratch requires a huge amount of data, but we only have 1,400 training photos. Transfer learning is the solution. We use a model that has already learned to recognize edges, textures, and shapes from millions of ImageNet photos, then teach it a new task. In this episode, we use the first method, Feature Extraction.
Create a model file underscore leaf dot py. The function creates a model that loads MobileNet V2 or ResNet 50 from Torch Vision, complete with ImageNet weights. The original classification head has 1,000 ImageNet classes, so we replace it with dropout and a linear layer of size 10 classes. Then all parameters in the model body are frozen with Requires Grad False. This is Feature Extraction. The model body only extracts features, and only the new head is trained.
Still in the same file, two helper functions. Open block will be used in the next episode for fine-tuning, which is to re-enable some of the last blocks in the model body. Count para to calculate the total number of parameters and those that are actually trained.
Now create a train file underscore leaf dot py. The accuracy function calculates the precision on a loader. Our train function is versatile. Number of epochs, learning rate, scheduler, data ratio, weight decay, and callback report. Optimizer Adam only receives parameters that Require Grad, and every time validation accuracy reaches a new record, the model is saved. This function is used again in episodes 4 and 5. The main part trains both models for 5 epochs, then draws the validation accuracy curve.
Run. MobileNetV2 has 2.2 million parameters, but only 12,810 are trained, 0.6%. ResNet50 has 23.5 million parameters, and only 20,000 are trained, 0.1%. See the results.
MobileNetV2 achieves the best validation accuracy of 75.7%, ResNet50 74%, and ResNet50 is about twice as slow per epoch. For 10 similar classes, these results are already quite good, but not enough yet. ImageNet features are learned from photos of everyday objects, not leaf diseases. Because MobileNetV2 is lighter, faster, and slightly more accurate, we continue with MobileNetV2. Done.
We have already used the pretrained ImageNet model from TorchVision, replaced the classification head, froze the model body, and compared MobileNetV2 with ResNet50. In the next episode, we significantly increase the accuracy by fine-tuning the upper layers and learning rate scheduling. Currently working on a thesis, dissertation, or AI research in the field of agricultural AI? Cerdas Inovasi Digital helps with deep learning implementation, from transfer learning with MobileNet and ResNet, fine-tuning, hyperparameter optimization with Optuna, up to web application and result writing, as well as opening deep learning courses with PyTorch. Want to master the entire series, from the Plan Village dataset to the web application for leaf disease detection? All 6 episodes, complete with PDF step-by-step guides and source code, are available for premium tutorial subscribers. Subscribe starting at Rp69,000 per month, save 28% with the 12-month package Or pay once Rp999.000 for lifetime access. Want just one class? Buy single class with lifetime access. Subscribe now on the premium page cerdasinovasidigital.com Contact our WhatsApp or visit cerdasinovasidigital.com Thank you for watching, see you in the next episode.
Type a question or keyword; we find the part of this episode that explains it and jump the video there.
Notes are saved with the current video time and are only visible to you.
Stuck on a step? Ask here; the instructor and other learners can answer.
No questions yet.

Cerdas Inovasi Digital Team
Software developers, BIM & 3D engineers, and AI practitioners
We build software, BIM models, games and AI automations for clients every day, and turn that hands-on work into step-by-step classes: every step is shown on screen and comes with a PDF guide you can keep.
See our clients →