更新时间: 试题数量: 购买人数: 提供作者:

有效期: 个月

章节介绍: 共有个章节

收藏
搜索
题库预览
第4题

第①问

编写代码,获取图像数据,打印出数据集中第一张图像的色彩通道数,将代码和打印的图片内容截图,并将截图直接粘贴至答案区。

第②问

编写代码,获取图像数据,打印出数据集中第一张图像的数据类型,将代码和打印的图片内容截图,并将截图直接粘贴至答案区。

第③问

编写代码,获取图像数据,打印出数据集中第一张图像的总像素,将代码和打印的图片内容截图,并将截图直接粘贴至答案区。

#任务一 import requests from PIL import Image import cv2 import numpy as np from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt # 系统代码 勿动 数据集准备 image_urls = [ 'https://cdn.tzspace.cn/exam/20240513-level3-exam/%E7%AC%AC%E5%9B%9B%E9%A2%98/%E7%90%83/basketball_1.png', 'https://cdn.tzspace.cn/exam/20240513-level3-exam/%E7%AC%AC%E5%9B%9B%E9%A2%98/%E7%90%83/basketball_2.png', 'https://cdn.tzspace.cn/exam/20240513-level3-exam/%E7%AC%AC%E5%9B%9B%E9%A2%98/%E7%90%83/basketball_3.png', 'https://cdn.tzspace.cn/exam/20240513-level3-exam/%E7%AC%AC%E5%9B%9B%E9%A2%98/%E7%90%83/basketball_4.png', 'https://cdn.tzspace.cn/exam/20240513-level3-exam/%E7%AC%AC%E5%9B%9B%E9%A2%98/%E7%90%83/basketball_5.png', ] # 系统代码 勿动 函数:从URL下载图片并转换为OpenCV格式 def download_image_cv2(url): resp = requests.get(url) image_array = np.asarray(bytearray(resp.content), dtype=np.uint8) image = cv2.imdecode(image_array, cv2.IMREAD_COLOR) return image # 系统代码 勿动 下载所有图片并转换格式,并存储图片名称 images_list = [] for url in image_urls: image = download_image_cv2(url) images_list.append((url, image)) first_image = images_list[0][1] # 任务一:补充<1>处,打印第一张图像的色彩通道数 print(f"第一张图像的色彩通道数: {first_image.【1】}") #任务一结束 # 任务二:打印第一张图像的数据类型 print(f"第一张图像的数据类型: {first_image.【2】}") #任务二结束 # 任务三:打印第一张图像的宽度和高度 height, width = 【3】 print(f"第一张图像的宽度: {width}, 高度: {height}") #任务三结束

第5题

第①问

编写代码,获取图像数据和标签显示数据集中第一张图像和标签,将代码和输出截图,并将截图直接粘贴至答案区

第②问

编写代码,对图像数据转换为array格式并进行归一化处理打印处理后的第一张图像的数据,将代码和输出截图,并将截图直接粘贴至答案区。

import requests import cv2 import numpy as np import matplotlib.pyplot as plt # ========== 系统提供代码 ========== image_urls = [ 'https://d.ifengimg.com/w1125_q90_webp/x0.ifengimg.com/ucms/2025_15/05B90418E325993E5D424B5EBBBD1ACA1576F059_size865_w2570_h1713.jpg', 'https://d.ifengimg.com/w1125_q90_webp/x0.ifengimg.com/ucms/2025_16/F97955E89EC3E77F14EAFA08F4F80AA82D500E4C_size89_w1267_h713.jpg', ] def download_image_cv2(url): resp = requests.get(url) image_array = np.asarray(bytearray(resp.content), dtype=np.uint8) image = cv2.imdecode(image_array, cv2.IMREAD_COLOR) return image images_list = [] for url in image_urls: image = download_image_cv2(url) images_list.append((url, image)) # ========== 新增标签定义 ========== labels = ['bike22', 'phone1'] # 标签 # 提取第一个图像 first_url, first_img = images_list[0] first_img_rgb = cv2.cvtColor(first_img, cv2.COLOR_BGR2RGB) # BGR转RGB # ========== 任务① ========== #修改【1】处代码,显示第一张图片 【1】(first_img_rgb) #修改【2】处代码,显示第一个label plt.title(f"Label: {【2】}") plt.axis('off') plt.show() #任务一结束 # ========== 任务② ========== # 修改【3】处代码,进行归一化处理 img_array = first_img_rgb.astype(np.float32)【3】 print("归一化后的图像数组:") print("形状:", img_array.shape) print("首10个像素值(R通道第一行):\n", img_array[0, :10, 0]) #任务二结束

第②问-修改配置文件

某网络购物平台,现需要线上客服机器人接待服务,缓解人工客服压力,要求该机器人能够实现售前咨询、售中指导、售后回访等功能。

请完成项目配置文件,并根据下列要求完成机器人对话配置,点击代码运行后,必须要实现:当用户提问中包含关键词“价格”时,机器人都能回答“你好!本公司有智能语音机器人产品为880元。”这样的提问和回复。

将截图图片粘贴至考试平台答案区,并提交。

# -*- coding: utf-8 -*-
import re
import random

class SimpleKernel:
def __init__(self):
self.categories = {}
self.last_response = None
self.variables = {}

def learn(self, aiml_content):
pattern = re.compile(r'<category>\s*<pattern>(.*?)</pattern>(?:\s*<that>(.*?)</that>)?\s*<template>(.*?)</template>\s*</category>', re.DOTALL)
matches = pattern.findall(aiml_content)

for match in matches:
pattern_text = match[0].strip().upper()
that_text = match[1].strip().upper() if match[1] else None
template_text = match[2].strip()
self.categories[(pattern_text, that_text)] = template_text

def respond(self, input_text):
input_text = input_text.strip().upper()

for (pattern_text, that_text), template_text in self.categories.items():
if re.match(pattern_text.replace('*', '.*'), input_text):
if that_text is None or (self.last_response and re.match(that_text.replace('*', '.*'), self.last_response)):
self.last_response = input_text
response = self.process_template(template_text)
return response
return "Sorry, I don't understand that."

def process_template(self, template):
if '<random>' in template:
choices = re.findall(r'<li>(.*?)</li>', template, re.DOTALL)
template = random.choice(choices)
template = re.sub(r'<get name="(.*?)"/>', lambda match: self.variables.get(match.group(1), ''), template)
return template

def set_variable(self, name, value):
self.variables[name] = value

# 修改下列 AIML 内容,完成问答配置
aiml_content = '''
<aiml version="1.0.1" encoding="UTF-8">
<category>
<pattern>HELLO</pattern>
<template>Hi there!</template>
</category>
<category>
<pattern>HOW ARE YOU</pattern>
<template>I'm doing well, thank you!</template>
</category>
<category>
<pattern>WHAT IS YOUR NAME</pattern>
<template>My name is Alice.</template>
</category>
<category>
<pattern>你多大了</pattern>
<template>
<random>
<li>哇, <get name="age"/> , 如花似玉的年龄.</li>
<li>你都 <get name="age"/> 了, 好老.</li>
<li><get name="age"/> , 我比你年轻好多好多.</li>
<li>哦,<get name="age"/> , 您学到的知识比我多得多呢.</li>
</random>
</template>
</category>
<category>
<pattern>*睡*</pattern>
<template>我是人工智能,不需要睡觉。不过,真希望自己也能做个美梦呢。。</template>
</category>
  【2】
</aiml>
'''

# 创建内核实例并加载 AIML 内容
alice = SimpleKernel()
alice.【1】(aiml_content) # learn
alice.set_variable("age", "25") # 设置变量年龄

# 模拟用户输入
user_inputs = [
"HELLO",
"HOW ARE YOU",
"WHAT IS YOUR NAME",
"你多大了",
"我在睡觉",
"你这个价格多少啊?",
"你这个价格有点贵啊!"
]

# 处理每个用户输入并打印响应
for user_input in user_inputs:
print(f"我是您的智能服务机器人,请您提问...>> {user_input}")
response = alice.respond(user_input)
print(response)

1 2