The CNN Image Classifier provides a RESTful API built with FastAPI for image classification. The API allows users to upload images and receive predictions with confidence scores.
http://localhost:8000
GET /Returns a welcome message and basic information about the API.
{
"message": "Welcome to the CNN Image Classification API",
"version": "1.0.0",
"endpoints": {
"predict": "/predict"
}
}POST /predictClassifies an uploaded image and returns the predicted class with confidence scores.
- Method:
POST - Content-Type:
multipart/form-data - Body:
file: Image file (supported formats: JPG, PNG)
{
"class": "airplane",
"confidence": 0.95,
"top_3_predictions": [
{
"class": "airplane",
"confidence": 0.95
},
{
"class": "bird",
"confidence": 0.03
},
{
"class": "cat",
"confidence": 0.02
}
]
}- No File Uploaded
{
"error": "No file uploaded"
}- Invalid File Type
{
"error": "Invalid file type. Supported formats: JPG, PNG"
}- Processing Error
{
"error": "Error processing image"
}curl -X POST "http://localhost:8000/predict" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "file=@path/to/your/image.jpg"import requests
url = "http://localhost:8000/predict"
files = {"file": open("path/to/your/image.jpg", "rb")}
response = requests.post(url, files=files)
print(response.json())const formData = new FormData();
formData.append('file', fileInput.files[0]);
fetch('http://localhost:8000/predict', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));Currently, there are no rate limits implemented. However, please be mindful of server resources when making requests.
The API supports CORS and can be accessed from any origin. For production deployment, you may want to restrict this to specific domains.
The API uses standard HTTP status codes:
- 200: Success
- 400: Bad Request
- 415: Unsupported Media Type
- 500: Internal Server Error
- File size limit: 10MB
- Supported file types: JPG, PNG
- Input validation for all requests
- Error messages are sanitized to prevent information leakage
- Authentication
- Rate limiting
- Batch processing
- Additional model endpoints
- Model versioning