Using pretrained DenseNet-121 for image classification
In this experiment, Google Colab is used to utilize GPU acceleration and achieve better training results in a shorter time.
The source code is in notebook format and can be directly opened on the Google Colab platform by running each code block sequentially.
(1) Data Processing
First, downloading food images dataset from Kaggle, and upload zip to Google Drive (compression speeds up the upload process), and then extract it.
Next, define some data augmentation operations, such as cropping and rotation.
Finally, extract the labels and put all the data into dataloaders.
(2) Model Building
The model consists of a pretrained DenseNet121 and a fully connected layer.
(3) Model Training
The loss function is cross-entropy, and the Adam optimizer is used.
(4) Model Testing