This repository contains three different implementations of image classification using deep learning techniques. Each script uses a different framework or approach to classify images based on folder names as labels.
keras_image_classifier.py
: A simple CNN image classifier using Keras/TensorFlow.pytorch_image_classifier.py
: A simple CNN image classifier using PyTorch.pytorch_image_classifier_resnet.py
: An advanced CNN image classifier using PyTorch with transfer learning.keras_image_classifier_resnet.py
: An advanced CNN image classifier using PyTorch with transfer learning.
For the image classification scripts to work properly, you need to organize your image dataset in a specific way. The structure depends on which script you're using:
Organize your images into folders, where each folder name represents a class label:
data_dir/
├── class1/
│ ├── image1.jpg
│ ├── image2.jpg
│ └── ...
├── class2/
│ ├── image1.jpg
│ ├── image2.jpg
│ └── ...
└── ...
Split your dataset into training and testing sets:
data_dir/
├── train/
│ ├── class1/
│ │ ├── image1.jpg
│ │ ├── image2.jpg
│ │ └── ...
│ ├── class2/
│ │ ├── image1.jpg
│ │ ├── image2.jpg
│ │ └── ...
│ └── ...
└── test/
├── class1/
│ ├── image1.jpg
│ ├── image2.jpg
│ └── ...
├── class2/
│ ├── image1.jpg
│ ├── image2.jpg
│ └── ...
└── ...
-
Clone this repository:
git clone https://github.com/yourusername/image-classification-scripts.git cd image-classification-scripts
-
Install the required dependencies (you may want to use a virtual environment):
pip install tensorflow torch torchvision numpy
-
Prepare your dataset as described above.
-
Update the
data_dir
variable in the script you want to use with the path to your dataset. -
Run the desired script:
python keras_image_classifier.py # or python keras_image_classifier_resnet.py # or python pytorch_image_classifier.py # or python pytorch_image_classifier_resnet.py
Feel free to modify the scripts to suit your needs. You can adjust parameters such as:
- Image dimensions
- Batch size
- Number of epochs
- Model architecture
- Learning rate and optimizer
Contributions to improve the scripts or add new features are welcome. Please feel free to submit a pull request or open an issue if you have any questions or suggestions.
This project is open-source and available under the MIT License.