Cloudflare Docs
Workers AI
Edit this page
Give us feedback
Set theme to dark (⇧+D)

resnet-50

Model ID: @cf/microsoft/resnet-50

50 layers deep image classification CNN trained on more than 1M images from ImageNet

More Information  

​​ Properties

Task Type: Image Classification

​​ Code Examples

Worker - TypeScript
export interface Env {
AI: Ai;
}
export default {
async fetch(request, env): Promise<Response> {
const res: any = await fetch("https://cataas.com/cat");
const blob = await res.arrayBuffer();
const inputs = {
image: [...new Uint8Array(blob)],
};
const response = await env.AI.run(
"@cf/microsoft/resnet-50",
inputs
);
return new Response(JSON.stringify(response));
},
} satisfies ExportedHandler<Env>;
curl
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/@cf/microsoft/resnet-50 \
-X POST \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--data-binary "@orange-llama.png"

​​ Response

[
{ "label":"PERSIAN CAT" ,"score":0.4071170687675476 },
{ "label":"PEKINESE", "score":0.23444877564907074 },
{ "label":"FEATHER BOA", "score":0.22562485933303833 },
{ "label":"POMERANIAN", "score":0.033316344022750854 },
{ "label":"JAPANESE SPANIEL", "score":0.024184171110391617 }
]

​​ API Schema

The following schema is based on JSON Schema

Input JSON Schema
{
"oneOf": [
{
"type": "string",
"format": "binary"
},
{
"type": "object",
"properties": {
"image": {
"type": "array",
"items": {
"type": "number"
}
}
},
"required": [
"image"
]
}
]
}
Output JSON Schema
{
"type": "array",
"contentType": "application/json",
"items": {
"type": "object",
"properties": {
"score": {
"type": "number"
},
"label": {
"type": "string"
}
}
}
}