Memuat
Memuat
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Class U-Net Brain Tumor Segmentation #5: Optimizing U-Net Hyperparameters with PSO & Grey Wolf Optimizer”.
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, the convergence curve of two metaheuristic algorithms, Particle Swarm Optimization and Gray Wolf Optimizer, which automatically search for the best combination of learning rate, number of filters, and dropout for UNET. The winner will be retrained and compared with other base models. Let's get started. Hello, welcome to episode five of the brain tumor segmentation series with metaheuristically optimized UNET. This is the core of our research innovation. In the previous episode, other base hyperparameters were chosen in a general way. The question is, is there a better combination? Trying all combinations is too expensive, as each trial means training UNET. This is where metaheuristics come into play, algorithms inspired by nature, searching for good solutions with a limited number of trials.
Create a file named metaheuristik.py First, Particle Swarm Optimization, inspired by a flock of birds. Each particle is one hyperparameter candidate, with position values ranging from 0-1 in each dimension. Particle velocity is influenced by three factors, inertia W, attraction to the personal best position or P-best, and attraction to the global best position or G-best. Coefficients C1 and C2 regulate the strength of these attractions. In each iteration, P-best is updated if the particle finds a better value.
Second, Gray Wolf Optimizer, inspired by the hierarchy of gray wolves when hunting. The three best wolves are called alpha, beta, and delta. They lead the hunt. The new position of each wolf is the average of three steps towards the three leaders. Parameter A decreases from 2 to 0. At the beginning, wolves explore widely, and at the end, they encircle the prey. Both functions return the best solution and its convergence curve.
Now create a file named optimasi_unet.py. The decode function translates the 0-1 position into hyperparameters. Learning rate on a logarithmic scale from 0.0002-0.01, number of filters 8-24, and dropout 0-0.3. The fitness function trains units using the train model function from episode 4, but only 3 epochs with half of the training data to make it faster, then returns the validation data. The results are saved in cache to avoid training the same combination twice.
We run PSO and GWO, each with 5 agents and 3 iterations, with the same initial population to ensure fairness. This process takes about 17 minutes on a CPU, so the video speeds it up. Check the terminal, each line is 1 unit being trained. The scores vary widely, from 0.06 to 0.67, proving that hyperparameters have a significant impact. PSO finds the best score of 0.673 with learning rate 0.00129, 18 filters, and dropout 0.16. GWO reaches 0.666. The convergence graph shows PSO rising faster, while GWO only jumps at the last iteration. PSO wins.
Create a file named train_optimal.py, which reads the optimization results and re-trains the unit fully, 15 epochs with all training data, using the winning hyperparameters. The best validation score is 0.767, slightly above the baseline 0.763. The graph compares the validation score curves of both. The difference in validation data is indeed small, but the actual evaluation is on the test data that hasn't been seen before, and that's what we do in the final episode.
Done. We have already written the PSO and GWO optimizers from scratch, designing the search space and fitness function, comparing convergence curves, and retrain the unit with the best hyperparameters. In the final episode, we evaluated both models on the test data using DAIS and IOU, viewing the segmentation result overlay, and compare before and after optimization. Working on a thesis, thesis, Or are you involved in AI research in the field of medical image segmentation? Cerdas Inovasi Digital helps with the implementation of deep learning, from UNET segmentation, metaheuristic optimization with PSO and GWO, until DAIS evaluation, IOU, and writing the results, as well as opening a deep learning course with PyTor. Want to master the entire series, From MRI brain dataset to a meta-optimized U-Net? All 6 episodes, complete with a step-by-step PDF guide and source code, Available for premium tutorial subscribers. Subscribe starting at 69 thousand rupiah per month, save 28 percent with the 12-month package, or one-time payment of 999 thousand for lifetime access. Want just one class? Buy single classes 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 →