{"id":21433040,"url":"https://github.com/llegomark/image-classification-resnet-50","last_synced_at":"2026-04-20T09:02:51.044Z","repository":{"id":233258674,"uuid":"786373194","full_name":"llegomark/image-classification-resnet-50","owner":"llegomark","description":"This project utilizes the Hono framework to build a Cloudflare Worker that exposes an API endpoint for image classification. It integrates with Cloudflare AI to run the Microsoft Vision Model ResNet-50 and classify images based on either image URLs or file uploads.","archived":false,"fork":false,"pushed_at":"2024-06-19T01:06:03.000Z","size":70,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-11T12:20:35.679Z","etag":null,"topics":["cloudflare","cloudflare-ai","cloudflare-workers","hono","honojs","resnet","resnet-50","resnet50"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/llegomark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-14T08:59:41.000Z","updated_at":"2025-05-22T10:18:45.000Z","dependencies_parsed_at":"2024-04-15T08:24:11.379Z","dependency_job_id":"d147c9b5-877d-422b-8638-fd676ca1c9bb","html_url":"https://github.com/llegomark/image-classification-resnet-50","commit_stats":null,"previous_names":["llegomark/image-classification-resnet-50"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/llegomark/image-classification-resnet-50","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llegomark%2Fimage-classification-resnet-50","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llegomark%2Fimage-classification-resnet-50/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llegomark%2Fimage-classification-resnet-50/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llegomark%2Fimage-classification-resnet-50/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/llegomark","download_url":"https://codeload.github.com/llegomark/image-classification-resnet-50/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llegomark%2Fimage-classification-resnet-50/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32040353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare","cloudflare-ai","cloudflare-workers","hono","honojs","resnet","resnet-50","resnet50"],"created_at":"2024-11-22T23:24:17.832Z","updated_at":"2026-04-20T09:02:51.024Z","avatar_url":"https://github.com/llegomark.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Image Classification with Microsoft Vision Model ResNet-50\n\nThe Microsoft Vision Model ResNet-50 is a powerful pretrained vision model created by the Multimedia Group at Microsoft Bing. It is a 50-layer deep convolutional neural network (CNN) trained on more than 1 million images from ImageNet. By leveraging multi-task learning and optimizing separately for four datasets, including ImageNet-22k, Microsoft COCO, and two web-supervised datasets containing 40 million image-label pairs, the model achieves state-of-the-art performance in image classification tasks.\n\nThis project utilizes the Hono framework to build a Cloudflare Worker that exposes an API endpoint for image classification. It integrates with Cloudflare AI to run the Microsoft Vision Model ResNet-50 and classify images based on either image URLs or file uploads.\n\n## Technologies Used\n\n- **Hono**: A lightweight web framework for building fast and scalable applications on Cloudflare Workers.\n- **Cloudflare Workers**: A serverless execution environment that allows running JavaScript and TypeScript code at the edge, close to users.\n- **Cloudflare AI**: A set of APIs and tools provided by Cloudflare for integrating AI capabilities into applications.\n\n## Features\n\n- Accepts both image URLs and file uploads for classification.\n- Validates input using Zod schema validation.\n- Supports CORS and CSRF protection middleware.\n- Implements JWT authentication middleware for secure access to the API.\n- Handles errors gracefully and returns appropriate error responses.\n- Provides an optional `model` parameter to specify the model for additional analysis.\n  - Supported models: `llama` and `gemma`.\n  - If the `model` parameter is not provided or is set to a value other than `llama` or `gemma`, only image classification is performed without additional analysis.\n\n## API Endpoint\n\n- **URL**: `/api/classify/:model?`\n  - `:model` (optional): Specifies the model to use for additional analysis. Supported values: `llama` and `gemma`.\n- **Method**: `POST`\n- **Authentication**: JWT token required in the `Authorization` header.\n- **Request Body**: JSON array of image objects, each containing either a `url` or `file` property.\n  - `url`: The URL of the image to classify (optional).\n  - `file`: The uploaded image file to classify (optional).\n- **Response**: JSON object containing an array of responses for each image.\n  - Each response includes:\n    - `classification`: An array of classification results, each containing a `label` and a `score`.\n    - `analysis` (optional): The analysis summary generated by the specified model, if a supported model is provided.\n\n## Usage\n\n1. Set up a Cloudflare Worker and configure the necessary environment variables:\n   - `AI`: Your Cloudflare AI API token.\n   - `JWT_SECRET`: The secret key used for JWT authentication.\n2. Deploy the worker code to your Cloudflare Worker.\n3. Make a POST request to the `/api/classify` endpoint with the following payload:\n\n   ```json\n   [\n   \t{\n   \t\t\"url\": \"https://example.com/image1.jpg\"\n   \t},\n   \t{\n   \t\t\"file\": \"\u003cuploaded_file\u003e\"\n   \t}\n   ]\n   ```\n\n   Replace `\u003cuploaded_file\u003e` with the actual file upload.\n\n   You can also specify an optional `model` parameter in the URL to use a specific model for analysis. The available models are `llama` and `gemma`. If the `model` parameter is not provided or is set to a value other than `llama` or `gemma`, only image classification will be performed without additional analysis.\n\n   Here are example cURL commands to classify images:\n\n   - Classify an image using a URL:\n\n     ```bash\n     curl -X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer \u003cyour-jwt-token\u003e\" -d '[{\"url\": \"https://example.com/image1.jpg\"}]' https://your-worker-url.com/api/classify\n     ```\n\n   - Classify an image using a file upload:\n\n     ```bash\n     curl -X POST -H \"Content-Type: multipart/form-data\" -H \"Authorization: Bearer \u003cyour-jwt-token\u003e\" -F \"file=@/path/to/image.jpg\" https://your-worker-url.com/api/classify\n     ```\n\n   - Classify an image using a URL with the `llama` model for analysis:\n\n     ```bash\n     curl -X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer \u003cyour-jwt-token\u003e\" -d '[{\"url\": \"https://example.com/image1.jpg\"}]' https://your-worker-url.com/api/classify/llama\n     ```\n\n   - Classify an image using a file upload with the `gemma` model for analysis:\n     ```bash\n     curl -X POST -H \"Content-Type: multipart/form-data\" -H \"Authorization: Bearer \u003cyour-jwt-token\u003e\" -F \"file=@/path/to/image.jpg\" https://your-worker-url.com/api/classify/gemma\n     ```\n\n   Replace `\u003cyour-jwt-token\u003e` with your actual JWT token and `https://your-worker-url.com` with the URL of your deployed Cloudflare Worker.\n\n4. The API will return a JSON response with the classification results and analysis (if applicable) for each image:\n   ```json\n   {\n   \t\"responses\": [\n   \t\t{\n   \t\t\t\"classification\": [\n   \t\t\t\t{\n   \t\t\t\t\t\"label\": \"dog\",\n   \t\t\t\t\t\"score\": 0.9\n   \t\t\t\t},\n   \t\t\t\t{\n   \t\t\t\t\t\"label\": \"animal\",\n   \t\t\t\t\t\"score\": 0.8\n   \t\t\t\t}\n   \t\t\t],\n   \t\t\t\"analysis\": \"The image contains a dog, which is a type of animal. The classification scores indicate a high confidence in the presence of a dog in the image.\"\n   \t\t},\n   \t\t{\n   \t\t\t\"classification\": [\n   \t\t\t\t{\n   \t\t\t\t\t\"label\": \"cat\",\n   \t\t\t\t\t\"score\": 0.95\n   \t\t\t\t},\n   \t\t\t\t{\n   \t\t\t\t\t\"label\": \"animal\",\n   \t\t\t\t\t\"score\": 0.85\n   \t\t\t\t}\n   \t\t\t],\n   \t\t\t\"analysis\": \"The image depicts a cat, which belongs to the animal category. The high classification scores suggest a strong likelihood of a cat being present in the image.\"\n   \t\t}\n   \t]\n   }\n   ```\n   If the `model` parameter is not provided or is set to a value other than `llama` or `gemma`, the `analysis` field will be absent in the response.\n\n## Limitations\n\n- The Microsoft Vision Model ResNet-50 is pretrained on a specific set of image categories. It may not perform well on images outside its training domain.\n- The model accepts only certain image formats, such as JPEG, PNG, and GIF. Other formats may not be supported.\n- The performance of the model may vary depending on the quality and resolution of the input images.\n\n## Contributing\n\nContributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllegomark%2Fimage-classification-resnet-50","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fllegomark%2Fimage-classification-resnet-50","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllegomark%2Fimage-classification-resnet-50/lists"}