# 训练数据集,VOC格式数据集, 训练数据取自 ImageSets/Main/train.txt' train_dataset = vocdataset(cfg, is_train=True, transform=transfrom(cfg, is_train=True), target_transform=targettransform(cfg)) # 测试数据集,VOC格式数据集, 测试数据取自 ImageSets/Main/eval.txt' test_dataset = vocdataset(cfg=cfg, is_train=False, transform=transfrom(cfg=cfg, is_train=False), target_transform=targettransform(cfg)) if __name__ == '__main__': """ 使用时,请先打开visdom 命令行 输入 pip install visdom 进行安装 输入 python -m visdom.server' 启动 """ # 首次调用会下载resnet预训练模型 # 实例化模型. 模型的具体各种参数在Config文件中进行配置 net = RetainNet(cfg) # 将模型移动到gpu上,cfg.DEVICE.MAINDEVICE定义了模型所使用的主GPU net.to(cfg.DEVICE.MAINDEVICE) # 初始化训练器,训练器参数通过cfg进行配置;也可传入参数进行配置,但不建议 trainer = Trainer(cfg) # 训练器开始在 数据集上训练模型 trainer(net, train_dataset)
# -*- coding: utf-8 -*- # @Author : LG from Model import RetainNet from Configs import _C as cfg # 实例化模型 net = RetainNet(cfg) # 使用cpu或gpu net.to('cuda') # 模型从权重文件中加载权重 net.load_pretrained_weight(cfg.FILE.MODEL_SAVE_ROOT + '/' + 'model_8000.pkl') video_path = '/home/chenshuo/Retinanet-Pytorch/test.mp4' # 进行检测, # if save_video_path不为None,则不保存视频,如需保存视频save_video_path=XXX.mp4 , # show=True,实时显示检测结果 net.Detect_video(video_path=video_path, score_threshold=0.02, save_video_path='/home/chenshuo/Retinanet-Pytorch/test1.mp4', show=False)
# -*- coding: utf-8 -*- # @Author : LG from Model import RetainNet from Configs import _C as cfg # 实例化模型 net = RetainNet(cfg) # 使用cpu或gpu net.to('cuda') # 模型从权重文件中加载权重 net.load_pretrained_weight('XXX.pkl') video_path = 'XXX.mp4' # 进行检测, # if save_video_path不为None,则不保存视频,如需保存视频save_video_path=XXX.mp4 , # show=True,实时显示检测结果 net.Detect_video(video_path=video_path, score_threshold=0.02, save_video_path=None, show=True)
# -*- coding: utf-8 -*- # @Author : LG from Model import RetainNet from Configs import _C as cfg from PIL import Image import matplotlib.pyplot as plt # 实例化模型 net = RetainNet(cfg) # 使用cpu或gpu net.to('cuda') # 模型从权重文件中加载权重 net.load_pretrained_weight('/home/chenshuo/Retinanet-Pytorch/Weights/trained1/model_20000.pkl') # 打开图片 image = Image.open("/home/chenshuo/RTTS/JPEGImages/BD_Baidu_145.png") # 进行检测, 分别返回 绘制了检测框的图片数据/回归框/标签/分数. drawn_image, boxes, labels, scores = net.Detect_single_img(image=image,score_threshold=0.5) plt.imsave('XXX_det.png',drawn_image) plt.imshow(drawn_image) plt.show()
from Model import RetainNet, Evaler from Data import vocdataset from Configs import _C as cfg from Data import transfrom, targettransform # 训练数据集,VOC格式数据集, 训练数据取自 ImageSets/Main/train.txt' train_dataset = vocdataset(cfg, is_train=True, transform=transfrom(cfg, is_train=True), target_transform=targettransform(cfg)) # 测试数据集,VOC格式数据集, 测试数据取自 ImageSets/Main/eval.txt' test_dataset = vocdataset(cfg=cfg, is_train=False, transform=transfrom(cfg=cfg, is_train=False), target_transform=targettransform(cfg)) if __name__ == '__main__': # 模型测试只支持GPU单卡或多卡,不支持cpu net = RetainNet(cfg) # 将模型移动到gpu上,cfg.DEVICE.MAINDEVICE定义了模型所使用的主GPU net.to(cfg.DEVICE.MAINDEVICE) # 模型从权重文件中加载权重 net.load_pretrained_weight('XXX.pkl') # 初始化验证器,验证器参数通过cfg进行配置;也可传入参数进行配置,但不建议 evaler = Evaler(cfg, eval_devices=None) # 验证器开始在数据集上验证模型 ap, map = evaler(model=net, test_dataset=test_dataset) print(ap) print(map)
from Model import RetainNet, Evaler from Data import vocdataset from Configs import _C as cfg from Data import transfrom, targettransform # 训练数据集,VOC格式数据集, 训练数据取自 ImageSets/Main/train.txt' train_dataset = vocdataset(cfg, is_train=True, transform=transfrom(cfg, is_train=True), target_transform=targettransform(cfg)) # 测试数据集,VOC格式数据集, 测试数据取自 ImageSets/Main/eval.txt' test_dataset = vocdataset(cfg=cfg, is_train=False, transform=transfrom(cfg=cfg, is_train=False), target_transform=targettransform(cfg)) if __name__ == '__main__': # 模型测试只支持GPU单卡或多卡,不支持cpu net = RetainNet(cfg) # 将模型移动到gpu上,cfg.DEVICE.MAINDEVICE定义了模型所使用的主GPU net.to(cfg.DEVICE.MAINDEVICE) # 模型从权重文件中加载权重 net.load_pretrained_weight(cfg.FILE.MODEL_SAVE_ROOT + '/' + 'model_20000.pkl') # 初始化验证器,验证器参数通过cfg进行配置;也可传入参数进行配置,但不建议 evaler = Evaler(cfg, eval_devices=None) # 验证器开始在数据集上验证模型 ap, map = evaler(model=net, test_dataset=test_dataset) print('ap: ', ap) print('map: ', map)
# -*- coding: utf-8 -*- # @Author : LG from Model import RetainNet from Configs import _C as cfg from PIL import Image import matplotlib.pyplot as plt # 实例化模型 net = RetainNet(cfg) # 使用cpu或gpu net.to('cuda') # 模型从权重文件中加载权重 net.load_pretrained_weight( '/home/super/PycharmProjects/Retinanet-Pytorch/Weights/trained/model_35.pkl' ) # 打开图片 image = Image.open( "/home/super/VOC_det/VOCdevkit/VOC2007/JPEGImages/000009.jpg") # 进行检测, 分别返回 绘制了检测框的图片数据/回归框/标签/分数. drawn_image, boxes, labels, scores = net.Detect_single_img(image=image, score_threshold=0.5) plt.imsave('XXX_det.jpg', drawn_image) plt.imshow(drawn_image) plt.show()