Coder Social home page Coder Social logo

Comments (4)

Fafa-DL avatar Fafa-DL commented on May 20, 2024

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

from awesome-backbones.

wangshiwei567 avatar wangshiwei567 commented on May 20, 2024

我已经读取了视频,并传给了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

from awesome-backbones.

Fafa-DL avatar Fafa-DL commented on May 20, 2024

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

from awesome-backbones.

wangshiwei567 avatar wangshiwei567 commented on May 20, 2024

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

from awesome-backbones.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.