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 “CNN-LSTM Deep Learning for Pneumonia Detection Class #3: Baseline CNN for Normal vs Pneumonia Classification”.
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, our self-made CNN baseline model with a validation accuracy of around 95% and a test accuracy of around 91%, complete with loss and accuracy graphs for each IPOC. This model serves as a benchmark for the hybrid CNN-LSTM model in the next episode. Let's start. Hello, welcome to episode three of the series on hybrid CNN-LSTM models for early detection of lung diseases. In research, a new model must always be compared with a baseline or reference model. In this episode, we build a simple convolutional neural network, train it with the data we have already preprocessed, measure its accuracy, and save it.
The files from the previous two episodes are already available, including datasiap.npz and dataset underscore paru.py. Create a new file called CNN underscore baseline.py. The model consists of three convolutional blocks. Each block contains conv2d of 3x3, batch norm to stabilize training, relu, and max pool that reduces the size to half, from 64 to 32, 16, then 8. The number of channels increases from 16, 32, up to 64. The classification part flattens the feature map, applies dropout of 30%, then linear to the two classes.
We need an accuracy function to evaluate the model. The model is switched to evaluation mode, so dropout is disabled and batch norm uses fixed statistics, then with torch.no_grad we calculate how many predictions are correct across the entire batch.
Now the training loop. Training data uses augmentation, validation data does not. Optimizer Adam with learning rate 1000 per one, and loss cross entropy. For each epoch, we calculate the average loss and validation accuracy. After 8 epochs, the model weights are saved to CNN underscore baseline dot pt, and the history is saved to a json file. Then we measure the accuracy on the test data and draw the learning curve. Check the terminal.
This model is small, only around 32 thousand parameters, but the validation accuracy has already risen to around 95% in a few epochs, and the test accuracy is around 91%. The loss curve decreases steadily, while the validation accuracy fluctuates slightly, which is normal for small validation data. Also note that the test accuracy is lower than the validation accuracy, because the class proportions in the test data are different. This is the reason we need clinical metrics in the evaluation episode.
Done. We have built a CNN baseline with batch normalization and dropout, written the training loop, evaluated accuracy, and saved the baseline model. In the next episode, we will design the main architecture of this research, Hybrid CNN LSTM. Working on your thesis, dissertation, or AI research in the field of medical imaging? Cerdas Inovasi Digital helps with deep learning implementation, from CNN, LSTM, hybrid models, up to Grad-CAM interpretation and result writing, as well as opening deep learning courses with Python. Want to master the entire series, from Röntgen dataset to evaluation and Grad-CAM? All six episodes, complete with step-by-step PDF 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 the single class with lifetime access. Subscribe now at the premium page cerdasinovasidigital.com Contact us via WhatsApp, or visit cerdasinovasidigital.com Thank you for watching, see you in the next episode. Thank you for watching!
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 →