{
  "schemaVersion": 1,
  "id": "3.2.1",
  "title": "图像识别评估系统交互流程设计",
  "durationMinutes": 20,
  "category": "ONNX推理与交互设计",
  "scenario": "图像识别评估系统是在深度学习技术日益成熟的背景下发展起来的，旨在解决传统图像识别方法在面对复杂场景和大规模数据集时的局限性。随着互联网和物联网技术的飞速发展，图像数据量呈指数级增长，对图像内容的自动理解和智能分析提出了更高的要求。ResNet作为一种深度卷积神经网络架构，凭借其深度残差连接机制，能够有效缓解梯度消失问题，实现更深层次的网络结构，从而捕获更加丰富和抽象的图像特征，极大地提高了图像识别的准确性和效率，推动了人工智能技术在现实世界中的广泛应用和商业化进程。\n\nAI模型说明：“resnet.onnx”模型是使用 Pytorch 框架和基于深度卷积神经网络网络训练得到的，专门用于进行图像识别。对应的标签文件为“labels.txt”。该模型的使用交互流程为：\n\n1)加载“resnet.onnx”模型和“labels.txt”类别标签；\n\n2)加载本地测试图片“img_test.jpg”，并进行预处理图像以符合模型输入要求；\n\n3)使用“resnet.onnx”模型对加载的图片进行识别；\n\n4)输出加载图片的识别结果（输出概率值最大的5组类别和对应概率值）\n\n你作为一名人工智能训练师，请完成以下工作任务：\n\n（1）补全该模型的使用交互流程对应的Python代码（3.2.1.ipynb），实现本地测试图片“img_test.jpg”的识别，将其识别结果截图保存为jpg格式文件，命名为3.2.1-1.jpg。\n\n（2）在上面的使用交互流程基础上，给出在图像识别评估系统中使用“resnet.onnx”模型的一种人机交互的最优方式，将其保存为docx文件，命名为3.2.1.docx。",
  "skillRequirements": "（1）能够确保模型在单一场景下稳定运行；\n\n（2）能通过分析，找到单一场景下人工和智能交互的最优方式。",
  "qualityIndicators": "（1）模型运行稳定，使用正常；\n\n（2）单一场景下人工和智能交互的最优方式切实可行。",
  "tasks": [
    {
      "id": "code-fill",
      "type": "code-fill",
      "title": "补全代码任务",
      "instructions": "依据公开题面和附件补全代码空位；仅检查完成度与提交格式，不公开标准内容。",
      "codeBlocks": [
        "import onnxruntime as ort\nimport numpy as np\nimport scipy.special\nfrom PIL import Image\n\n\n# 预处理图像\ndef preprocess_image(image, resize_size=256, crop_size=224, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]):\n  image = image.resize((resize_size, resize_size), Image.BILINEAR)\n  w, h = image.size\n  left = (w - crop_size) / 2\n  top = (h - crop_size) / 2\n  image = image.crop((left, top, left + crop_size, top + crop_size))\n  image = np.array(image).astype(np.float32)\n  image = image / 255.0\n  image = (image - mean) / std\n  image = np.transpose(image, (2, 0, 1))\n  image = image.reshape((1,) + image.shape)\n  return image\n\n\n# 模型加载 2分\nsession = _________________\n\n\n# 加载类别标签\nlabels_path = 'labels.txt'\nwith open(labels_path) as f:\n  labels = [line.strip() for line in f.readlines()]\n\n\n# 获取模型输入和输出的名称\ninput_name = session.get_inputs()[0].name\noutput_name = session.get_outputs()[0].name\n\n\n# 加载图片 2分\nimage = _________________('RGB')\n\n\n# 预处理图片 2分\nprocessed_image = _________________\n\n\n# 确保输入数据是 float32 类型\nprocessed_image = processed_image.astype(np.float32)\n\n\n# 进行图片识别 2分\noutput = _________________([output_name], {input_name: processed_image})[0]\n\n\n# 应用 softmax 函数获取概率 2分\nprobabilities = _________________(output, axis=-1)\n\n\n# 获取最高的5个概率和对应的类别索引 3分\ntop5_idx = _________________[-5:][::-1]\ntop5_prob = _________________\n\n\n# 打印结果\nprint(\"Top 5 predicted classes:\")\nfor i in range(5):\n  print(f\"{i+1}: {labels[top5_idx[i]]} - Probability: {top5_prob[i]}\")\n"
      ],
      "blanks": [
        {
          "id": "blank-1",
          "block": 1,
          "placeholder": "_________________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-2",
          "block": 1,
          "placeholder": "_________________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-3",
          "block": 1,
          "placeholder": "_________________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-4",
          "block": 1,
          "placeholder": "_________________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-5",
          "block": 1,
          "placeholder": "_________________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-6",
          "block": 1,
          "placeholder": "_________________",
          "gradingMode": "completion-and-format-only"
        },
        {
          "id": "blank-7",
          "block": 1,
          "placeholder": "_________________",
          "gradingMode": "completion-and-format-only"
        }
      ]
    },
    {
      "id": "3-2-response",
      "type": "rubric-response",
      "title": "交互方案设计",
      "instructions": "说明代码功能对应的人机交互流程。",
      "sections": [
        {
          "id": "response",
          "label": "作答内容"
        }
      ],
      "rubric": [
        {
          "id": "criterion-1",
          "label": "输入与格式校验清晰",
          "weight": 25
        },
        {
          "id": "criterion-2",
          "label": "执行进度和状态反馈完整",
          "weight": 25
        },
        {
          "id": "criterion-3",
          "label": "结果展示可理解",
          "weight": 25
        },
        {
          "id": "criterion-4",
          "label": "包含异常处理与人工确认",
          "weight": 25
        }
      ]
    },
    {
      "id": "artifact-submission",
      "type": "artifact-submission",
      "title": "选择结果文件",
      "instructions": "文件仅在本机选择并校验，不上传，也不持久化文件内容。",
      "items": [
        {
          "id": "artifact-1",
          "label": "提交文件：3.2.1-1.jpg",
          "filename": "3.2.1-1.jpg",
          "extensions": [
            ".jpg"
          ],
          "minCount": 1,
          "maxCount": 1,
          "maxSize": 104857600
        },
        {
          "id": "artifact-2",
          "label": "提交文件：3.2.1.docx",
          "filename": "3.2.1.docx",
          "extensions": [
            ".docx"
          ],
          "minCount": 1,
          "maxCount": 1,
          "maxSize": 104857600
        }
      ]
    }
  ],
  "attachments": [
    {
      "name": "3.2.1.docx",
      "url": "assets/3.2.1/3.2.1.docx",
      "size": 14594,
      "sha256": "e3ac2b62921c2d2592b0740165d86aaefa3f7e87bbafb33e0157f226c25b2ab4",
      "mime": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
    },
    {
      "name": "3.2.1.ipynb",
      "url": "assets/3.2.1/3.2.1.ipynb",
      "size": 2831,
      "sha256": "735fe70d5c98cd7f77f4ca600891453bf87d1e7aec6606d3d1d71e45effe1c1e",
      "mime": "application/x-ipynb+json"
    },
    {
      "name": "3.2.1.md",
      "url": "assets/3.2.1/3.2.1.md",
      "size": 2455,
      "sha256": "37f49910ace48bce79f0e58c603a1521c49686c180538c0988991ecedf593b24",
      "mime": "text/markdown"
    },
    {
      "name": "img_test.jpg",
      "url": "assets/3.2.1/img_test.jpg",
      "size": 150351,
      "sha256": "d39697e9ee9f37371e13f50c33e6677275fe28e11839173d37ac98cf432d83d1",
      "mime": "image/jpeg"
    },
    {
      "name": "labels.txt",
      "url": "assets/3.2.1/labels.txt",
      "size": 10472,
      "sha256": "1f386e0d1cb6e28b9c2dac651c3dea6801e98ad1b41a14ce6bb1a093d72069f5",
      "mime": "text/plain"
    },
    {
      "name": "resnet.onnx",
      "url": "assets/3.2.1/resnet.onnx",
      "size": 102583340,
      "sha256": "af16a04a6ec48ac494065d4439fe9dea590d337b9ca6dc328160ccf04a217b9c",
      "mime": "application/octet-stream"
    }
  ],
  "grading": {
    "mode": "completion-and-format-only"
  },
  "review": {
    "status": "approved",
    "notice": "模型仅按需下载，网页不执行 ONNX 推理。",
    "conflicts": []
  },
  "contentVersion": "3522c58760b4ca3c"
}
