Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

您好,我想问一下怎么使用single_test.py推理视频 #8

Closed
wangshiwei567 opened this issue Aug 4, 2022 · 4 comments
Closed

Comments

@wangshiwei567
Copy link

您好,我想问一下怎么使用single_test.py推理视频

@Fafa-DL
Copy link
Owner

Fafa-DL commented Aug 4, 2022

这个问题以前有人私信问过我,当时手把手教他改了,你只需要读取视频为图片序列后再逐一检测和显示就行,如果需要的话我还是上传一个视频检测文件吧

@wangshiwei567
Copy link
Author

我已经读取了视频,并传给了inference_model,但出现了报错,找不到解决方法。
`import time
from argparse import ArgumentParser
import os
import sys
import cv2
sys.path.insert(0, os.getcwd())
import torch

from utils.inference import inference_model, init_model, show_result_pyplot
from utils.train_utils import get_info, file2dict
from models.build import BuildNet

def main():

video = '/home/sw/PycharmProjects/data/2021115163527.mp4'
config = '/home/sw/PycharmProjects/Classification/Awesome-Backbones-0.6.0/models/shufflenet/shufflenet_v2.py'
device = 'cuda:0'
save_path = './log'
classes_map = '../datas/annotations.txt'

classes_names, _ = get_info(classes_map)
# build the model from a config file and a checkpoint file
model_cfg, train_pipeline, val_pipeline, data_cfg, lr_config, optimizer_cfg = file2dict(config)
if device is not None:
    device = torch.device(device)
else:
    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

model = BuildNet(model_cfg)
model = init_model(model, data_cfg, device=device, mode='eval')

cap=cv2.VideoCapture(video)
while True:
    flag, frame = cap.read()
    if not flag:
        break
    t1 = time.time()
    # test a single image
    frame = torch.from_numpy(frame)
    result = inference_model(model, frame, val_pipeline, classes_names)

    show_result_pyplot(model, img, result, out_file=save_path)

if name == 'main':
main()`

image

@Fafa-DL
Copy link
Owner

Fafa-DL commented Aug 4, 2022

已更新,请拉取最新版本,或者单独下载tools/video_test.py以及更新utils/inference.py,如果解决了你的问题还麻烦在这里给个回复哈

@wangshiwei567
Copy link
Author

您好,已经可以推理视频了,非常感谢。

@Fafa-DL Fafa-DL closed this as completed Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants