This project focuses on creating a machine learning model that classifies images of dogs and cats. The model is encapsulated within a Python package, making it easy to install and use. The package employs TensorFlow for model training and inference, while OpenCV and Pillow are utilized for image processing. It is distributed via PyPI (Python Package Index).
Project description
Dog-Cat Classifier Python Package This project involves creating a machine learning model to classify images of dogs and cats. The model is packaged into a Python library for easy installation and usage. The library uses TensorFlow for the model, OpenCV and Pillow for image processing, and is distributed via PyPI.
Project Structure The project is organized in the following structure:
bash Copy code dogcat_classifier/ │ ├── dogcat_classifier/ # Main package folder │ ├── init.py # Marks this directory as a Python package │ ├── classifier.py # Contains the predict_image function and model loading logic │ ├── model.h5 # Pre-trained TensorFlow model │ ├── test_predict.py # Sample test file for predictions ├── dog.jpg # Sample image for testing ├── README.md # Project description and usage details ├── setup.py # Configuration for building and installing the package ├── requirements.txt # Project dependencies ├── MANIFEST.in # Ensures non-code files are included in the package ├── dist/ # Built distributions (created after running build commands) ├── build/ # Temporary build artifacts └── *.egg-info # Metadata for the package Steps to Build and Distribute the Package Initialize the Project:
Set up the project folder with necessary files like setup.py, classifier.py, model.h5, etc., to create the Python package. setup.py contains the package's metadata and dependencies. classifier.py includes the core functionality to load the trained model and classify images. Install Dependencies:
Install necessary dependencies using: bash Copy code pip install tensorflow pillow numpy matplotlib scikit-learn opencv-python setuptools wheel twine Build the Package:
Use the following command to build the package using setup.py: bash Copy code python setup.py sdist bdist_wheel This will generate the distributable .tar.gz and .whl files in the dist/ folder. Test the Package Locally:
Install the package locally to ensure everything works as expected: bash Copy code pip install . Test the functionality using test_predict.py, which tests the model's prediction on an image (dog.jpg). Upload the Package to PyPI:
After testing, upload the package to PyPI using Twine: bash Copy code python -m twine upload dist/* Verify the Package on PyPI:
Once uploaded, install the package from PyPI to verify that it works: bash Copy code pip install dogcat-classifier How to Use the Package Once the package is installed, you can use it to classify images of dogs and cats. Here's how you can do it:
python Copy code from dogcat_classifier.classifier import predict_image
Path to an image
image_path = 'path_to_your_image.jpg'
Predict whether the image is a dog or cat
result = predict_image(image_path)
print(f'The image is a {result}.') Why This Approach? Why Use python setup.py sdist bdist_wheel? The setup.py command generates the distribution files (i.e., .tar.gz and .whl), which are needed for uploading to PyPI.
Why Upload with twine? Twine securely handles the upload of your package to PyPI, ensuring that package files and credentials are properly managed.
Commands Used Install dependencies:
bash Copy code pip install tensorflow pillow numpy matplotlib scikit-learn opencv-python setuptools wheel twine Build the package:
bash Copy code python setup.py sdist bdist_wheel Upload to PyPI:
bash Copy code python -m twine upload dist/* Install locally for testing:
bash Copy code pip install . Test the package:
bash Copy code python test_predict.py
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dogcat_classifier-0.3.tar.gz.
File metadata
- Download URL: dogcat_classifier-0.3.tar.gz
- Upload date:
- Size: 8.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
beaad7cde751e01cbe64f03dcac3b4626534b85672bca8f1b3d513377c2d29be
|
|
| MD5 |
499eec30597c6498a2adda663fb43171
|
|
| BLAKE2b-256 |
ceb820db3949a35e75dd7ac4d8a726e78bf477068107780606920b6b1c70e038
|
File details
Details for the file dogcat_classifier-0.3-py3-none-any.whl.
File metadata
- Download URL: dogcat_classifier-0.3-py3-none-any.whl
- Upload date:
- Size: 8.5 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9efde21e69b3ef5d9081e0d9130d956ec59ca073e798545492b3d61a42648d87
|
|
| MD5 |
f87542ef3f04483b83a0889c32d1a24e
|
|
| BLAKE2b-256 |
84e2546866e83917fa13548cdb22d5d30993e747dd62cd0d8245c944156f76eb
|