零基础实践深度学习 第四章:目标检测YOLOv3(下) - AI识虫比赛
文档简介:
查看环境并准备数据:
# 查看当前挂载的数据集目录, 该目录下的变更重启环境后会自动还原。
# View dataset directory. This directory will be recovered automatically after resetting environment.
!ls /home/aistudio/data
查看环境并准备数据
# 查看当前挂载的数据集目录, 该目录下的变更重启环境后会自动还原 # View dataset directory.
This directory will be recovered automatically after resetting environment. !ls /home/aistudio/data
data67206 data69377
# 查看工作区文件, 该目录下的变更将会持久保存. 请及时清理不必要的文件, 避免加载过慢.
# View personal work directory. All changes under this directory will be kept even
after reset. Please clean unnecessary files in time to speed up environment loading. !ls /home/aistudio/work
# 将数据解压缩到 /home/aistudio/work目录下面 # 初次运行时需要将代码注释取消 !
unzip -d /home/aistudio/work /home/aistudio/data/data67206/insects.zip
# 进入工作目录 /home/aistudio/work %cd /home/aistudio/work
/home/aistudio/work
# 查看工作目录下的文件列表 !ls
!python train.py
# 在测试集test上评估训练模型,image_dir指向测试集集路径,weight_file指向要使用的权重路径。
# 参加比赛时需要在测试集上运行这段代码,并把生成的pred_results.json提交上去 !python eval.py
--image_dir=insects/test/images --weight_file=yolo_epoch50.pdparams
# 在验证集val上评估训练模型,image_dir指向验证集路径,weight_file指向要使用的权重路径。
!python eval.py --image_dir=insects/val/images --weight_file=yolo_epoch50.pdparams
!python calculate_map.py --anno_dir=insects/val/annotations/xmls/ --pred_result=pred_results.json
Accumulating evaluatation results... mAP(0.50, 11point) = 71.97
!python predict.py --image_name=./insects/test/images/3157.jpeg --weight_file=./yolo_epoch50.pdparams
# 预测结果保存在“/home/aistudio/work/output_pic.png"图像中,运行下面的代码进行可视化
# 可视化检测结果 from PIL import Image import matplotlib.pyplot as plt
img = Image.open("/home/aistudio/work/output_pic.png")
plt.figure("Object Detection", figsize=(15, 15)) # 图像窗口名称 plt.imshow(img)
plt.axis('off') # 关掉坐标轴为 off plt.title('Bugs Detestion') # 图像题目 plt.show()

<Figure size 1080x1080 with 1 Axes>