Python课后习题训练记录Day194

1.练习项目 :

练习使用Python语言

2.开始练习

(1)源码 :

from torchvision.datasets import VOCDetection

import torchvision.transforms as transforms

import numpy as np

import matplotlib.pyplot as plt

transform = transforms.Compose([

transforms.ToTensor(),

])

下载 VOC 2007 数据集

train_data = VOCDetection(root='./data',

year='2007',

image_set='train',

download=True,

transform=transform)

def display_images(image_list=None, title=None):

if image_list is None:

image_list = \[\]

if title is None:

title = ""

(False,True)

if not any(isinstance(i, list) for i in image_list):

image_list = image_list # img,img,img => \[img,img,img]

rows = len(image_list)

cols = max(len(row) if isinstance(row, list) else 1 for row in image_list)

plt.suptitle(title)

fig, ax = plt.subplots(rows, cols)

确保 ax 是 2 维数组

ax => \[ax] , ax => \[ax]

ax = np.atleast_2d(ax)

for i, row in enumerate(image_list):

if not isinstance(row, list):

row = row

for j, img in enumerate(row):

axi, j.imshow(img)

axi, j.axis("off")

for j in range(len(row), cols):

axi, j.axis("off")

plt.tight_layout()

plt.show()

def main():

images = \[\]

for i in range(5):

image, ann = train_datai

images.append(image.permute(1, 2, 0))

print(image.shape, ann)

display_images(images)

if name == "main":

main()

(2)检验结果

对此代码进行检验,检验后无报错,运行此代码,运行结果正确。

(3)练习心得:

注意每段代码末尾的分号是否存在 ,如不存在则需即使补充;输入法 是否切换为英语模式;语法是否错误。

相关推荐
happylifetree12 小时前
Python09:核心语法-数据存储与运算-字面量
python
心之语歌13 小时前
Tkinter 画布基本梳理
运维·服务器·python
Wx-bishekaifayuan13 小时前
django个性化旅游路线推荐平台49005-计算机课程设计、毕业设计
spring boot·后端·python·django·课程设计·express·旅游
一见已难忘14 小时前
产业AI落地技术解析:边缘部署、工业视觉检测与多传感器融合预警的工程实践(燎原:我看见的智能中国)
人工智能·计算机视觉·视觉检测
小白快快跑哦14 小时前
python-字符串全解(六):正则表达式-量词
python·正则表达式·字符串
禹凕14 小时前
机器学习之Selenium(Machina Learning about Selenium)
爬虫·python·selenium·测试工具·机器学习
ebiobiz16 小时前
基于 GD32 Embedded Builder (GEB) 与 Nimmake 的 MCU 工程搭建指南
c++·python·单片机·嵌入式硬件·mcu
老歌老听老掉牙17 小时前
穿越时空的物流密码:VRP与VRPTW的深度剖析及实战求解
python·物流·vrp
FYKJ_201017 小时前
django电影推荐系统55066-计算机课程设计、毕业设计
vue.js·spring boot·python·mysql·typescript·spark·django
ShyanZh17 小时前
【Python3基础】13-Python 常用设计模式
开发语言·python·设计模式