{
  "schemaVersion": 1,
  "id": "3.2.3",
  "title": "面部表情识别系统交互流程设计",
  "durationMinutes": 20,
  "category": "代码实现与交互设计",
  "scenario": "面部表情识别系统是一种先进的计算机视觉技术，它能够分析人脸的微表情，识别出诸如快乐、悲伤、惊讶等基本情绪。通过捕捉和解读面部特征，如眼睛、眉毛和嘴部的动作，这类系统能在实时或预录的视频中判断人的情感状态，广泛应用于人机交互、市场调研、医疗健康监测、安全监控及教育科技等多个领域，为提升用户体验、增进情感智能和优化社会服务提供了有力工具。\n\nAI模型说明：提供的已训练的模型“emotion-ferplus.onnx”，其专门用于进行面部表情识别。定义情感类别与数字标签的映射表为{'neutral':0, 'happiness':1, 'surprise':2, 'sadness':3, 'anger':4, 'disgust':5, 'fear':6, 'contempt':7}。\n\n该模型的使用交互流程为：\n\n1)加载模型“emotion-ferplus.onnx”和加载情感类别与数字标签的映射表；\n\n2)加载一张本地图片“img_test.png”，并预处理图像；\n\n3)使用已训练的模型对图片面部表情识别；\n\n4)输出识别后的表情标签。\n\n你作为一名人工智能训练师，请完成以下工作任务：\n\n（1）补全该模型的使用交互流程对应的Python代码（3.2.3.ipynb），实现本地测试图片“img_test.png”的识别，将其识别结果截图保存为jpg格式文件，命名为3.2.3-1.jpg。\n\n（2）在上面的使用交互流程基础上，给出在面部表情识别系统中使用“emotion-ferplus.onnx”模型的一种人机交互的最优方式，将其保存为docx文件，命名为3.2.3.docx。",
  "skillRequirements": "（1）能够确保模型在单一场景下稳定运行；\n\n（2）能通过分析，找到单一场景下人工和智能交互的最优方式。",
  "qualityIndicators": "（1）模型运行稳定，使用正常；\n\n（2）单一场景下人工和智能交互的最优方式切实可行。",
  "tasks": [
    {
      "id": "code-fill",
      "type": "code-fill",
      "title": "补全代码任务",
      "instructions": "依据公开题面和附件补全代码空位；仅检查完成度与提交格式，不公开标准内容。",
      "codeBlocks": [
        "# 导入必要的库\nimport numpy as np\nfrom PIL import Image\nimport onnxruntime as ort\n\n\n# 定义预处理函数，用于将图片转换为模型所需的输入格式\ndef preprocess(image_path):\n    input_shape = (1, 1, 64, 64)    # 模型输入期望的形状，这里是 (N, C, H, W)，N=batch size, C=channels, H=height, W=width\n    img = Image.open(image_path).convert('L')    # 打开图像文件并将其转换为灰度图  1分\n    img = img.resize((64, 64), Image.Resampling.LANCZOS)    # 调整图像大小到模型输入所需的尺寸\n    img_data = np.array(img, dtype=np.float32)    # 将PIL图像对象转换为numpy数组，并确保数据类型是float32\n    # 调整数组的形状以匹配模型输入的形状\n    img_data = np.expand_dims(img_data, axis=0)  # 添加 batch 维度\n    img_data = np.expand_dims(img_data, axis=1)  # 添加 channel 维度\n    assert img_data.shape == input_shape, f\"Expected shape {input_shape}, but got {img_data.shape}\"    # 确保最终的形状与模型输入要求的形状一致\n    return img_data    # 返回预处理后的图像数据\n\n\n# 定义情感类别与数字标签的映射表 3分\nemotion_table = {____________}\n\n\n# 加载模型 3分\nort_session = ____________    # 使用onnxruntime创建一个会话，用于加载并运行模型\n\n\n# 加载本地图片并进行预处理 3分\ninput_data = ____________\n\n\n# 准备输入数据，确保其符合模型输入的要求\nort_inputs = {ort_session.get_inputs()[0].name: input_data}    # ort_session.get_inputs()[0].name 是获取模型的第一个输入的名字\n\n\n# 运行模型，进行预测 3分\nort_outs = ____________(None, ____________)\n\n\n# 解码模型输出，找到预测概率最高的情感类别 3分\npredicted_label = ____________(ort_outs[0])\n\n\n# 根据预测的标签找到对应的情感名称 3分\npredicted_emotion = ____________[predicted_label]\n\n\n# 输出预测的情感\nprint(f\"Predicted emotion: {predicted_emotion}\")\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.3-1.jpg",
          "filename": "3.2.3-1.jpg",
          "extensions": [
            ".jpg"
          ],
          "minCount": 1,
          "maxCount": 1,
          "maxSize": 104857600
        },
        {
          "id": "artifact-2",
          "label": "提交文件：3.2.3.docx",
          "filename": "3.2.3.docx",
          "extensions": [
            ".docx"
          ],
          "minCount": 1,
          "maxCount": 1,
          "maxSize": 104857600
        }
      ]
    }
  ],
  "attachments": [
    {
      "name": "3.2.3.docx",
      "url": "assets/3.2.3/3.2.3.docx",
      "size": 14606,
      "sha256": "11c1896af32500a0bce9a152e6798e56930b01316673baa3f9d1a6f94ccb81e7",
      "mime": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
    },
    {
      "name": "3.2.3.ipynb",
      "url": "assets/3.2.3/3.2.3.ipynb",
      "size": 3183,
      "sha256": "0f4eb0e98852210f420c2d7e6738e1c4fcad50eeb5c5ac63f2a7fa8fa9f8ea1f",
      "mime": "application/x-ipynb+json"
    },
    {
      "name": "3.2.3.md",
      "url": "assets/3.2.3/3.2.3.md",
      "size": 2278,
      "sha256": "273ac997c5d2980289b446d0f7526779d3728dd506a87ca5a16b8475732a6deb",
      "mime": "text/markdown"
    },
    {
      "name": "emotion-ferplus.onnx",
      "url": "assets/3.2.3/emotion-ferplus.onnx",
      "size": 35040571,
      "sha256": "a2a2ba6a335a3b29c21acb6272f962bd3d47f84952aaffa03b60986e04efa61c",
      "mime": "application/octet-stream"
    },
    {
      "name": "img_test.png",
      "url": "assets/3.2.3/img_test.png",
      "size": 17697,
      "sha256": "7e688ab62e96522f26d84cc0178621794c5f2f705e6a323ded11f3f668a6e124",
      "mime": "image/png"
    }
  ],
  "grading": {
    "mode": "completion-and-format-only"
  },
  "review": {
    "status": "approved",
    "notice": "由公开题面通用生成，未使用答案树。",
    "conflicts": []
  },
  "contentVersion": "18828f3e56971fe2"
}
