github地址:https://github.com/18150167970/pytorch-yolov3-modifiy
预测完,只要读取模型,然后进行预测就ok了.
1.读模型
# Set up model
model = Darknet(opt.model_config_path)
model.load_weights(opt.weight_path)
model.cuda()
model.eval() #
2.读数据
dataset = Datasets(opt.valid)
dataloader = torch.utils.data.DataLoader(
dataset, batch_size=opt.batch_size, shuffle=False)
3.预测并绘图
for batch_i, (img_paths, input_imgs, targets) in enumerate(dataloader):
# Configure input
input_imgs = input_imgs.type(Tensor)
# Get detections
with torch.no_grad():
detections = model(input_imgs)
detections = non_max_suppression(
detections, 80, 0.8, 0.4)
# Log progress
# 绘制预测和真值图像
draw_predict(input_imgs, detections, img_paths)
draw_pre