Hi! In this project, I will guide you to organize CelebA dataset for each attributes and build binary image classifier in PyTorch.
I will follow 3 steps;
Firstly, we need to download CelebA Align&Cropped Images from here. Also, we will download the list_attr_celeba.csv file here to prepare dataset using the features. You need to place both of these folder to root. In csv file, -1 and 1 means that attributes status. In this project, I chose the beard and mustache as an attributes. You can change them in the project you will do yourself. If you want to change, you can modify OrganizeAttributes.py
file. Then run the file. Our train dataset ready. We will place both Yes and No folders into one training folder. Then we will create our test data with using OrganizeTest.py
file. I selected 2000 test data for each Yes and No folder. You can modify your own. Finally our train and test datasets are ready.
Now, we will create our network in BinaryClassifier.py
file. There are some parameters that you can modify. I used my owns. Also, you can modify network with respect to your project. When you run file, you will see the summary of models. In my computer, I have GTX 1050Ti and training starting in almost 200 seconds.
Epoch 1/50, Training Loss: 0.417, Training Accuracy: 84.000, Testing Loss: 0.034, Testing Acc: 50.000, Time: 245.3589s
Epoch 2/50, Training Loss: 0.382, Training Accuracy: 84.000, Testing Loss: 0.023, Testing Acc: 58.000, Time: 231.649s
After training finished, we will try to use our model for classification. I am going to use MTCNN for detect face and cropping bounding box before insert image into model. In UseClassifier.py
we insert input image to model for prediction.
- Torch
- Torchvision
- Matplotlib
- Numpy
- MTCNN
- Opencv-Python
- Pillow
- Pandas
pip install -r requirements.txt
Your folder should be like image;