keras-yolov3にて画像ファイルを入力後、実行すると以下が表示されます。
解決方法がわかりませんので、アドバイス頂けると幸いです。
実行手順
1.python yolo_video.py --image
2.実行すると以下のような表示がされるので,使用したい画像のパスを入力してenterを押せば処理が行われます.
3.Image detection mode
Ignoring remaining command line arguments: ./path2your_video,
2019-11-20 00:28:38.457780: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
model_data/yolo.h5 model, anchors, and classes loaded.
Input image filepath:
4.画像を指定し、実行すると以下のエラーが出力される
5.Traceback (most recent call last):
File "yolo_video.py", line 77, in <module>
detect_img(YOLO(**vars(FLAGS)))
File "yolo_video.py", line 19, in detect_img
cv2.imwrite(file_path + "_out" + ext, np.asarray(r_image)[..., ::-1])
TypeError: Expected Ptrcv::UMat for argument '%s'
*line19,line77はプログラムの右端に記載してあります。
------開発環境------
python3.7
cuda10.0
cudnn7.7
tensorflow-gpu13.1
Keras 2.1.6
opencv-python 4.1.2.30
pillow 6.2.1
matplotlib 3.1.2
numpy 1.17.4
ーーーーーーーーーーーターミナル上のエラー ーーーーーーーーーーーー
Traceback (most recent call last):
File "yolo_video.py", line 77, in <module>
detect_img(YOLO(**vars(FLAGS)))
File "yolo_video.py", line 19, in detect_img
cv2.imwrite(file_path + "_out" + ext, np.asarray(r_image)[..., ::-1])
TypeError: Expected Ptrcv::UMat for argument '%s'
-----プログラム-----
import sys,os
import argparse
from yolo import YOLO, detect_video
from PIL import Image
import numpy as np
import cv2
def detect_img(yolo):
while True:
img = input('Input image filepath:')
try:
image = Image.open(img)
except:
print('Open Error! Try again!')
continue
else:
r_image = yolo.detect_image(image)
file_path, ext = os.path.splitext(img)
[line19] cv2.imwrite(file_path + "_out" + ext, np.asarray(r_image)[..., ::-1])
r_image.show()
yolo.close_session()
FLAGS = None
if name == 'main':
# class YOLO defines the default value, so suppress any default here
parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
'''
Command line options
'''
parser.add_argument(
'--model', type=str,
help='path to model weight file, default ' + YOLO.get_defaults("model_path")
)
parser.add_argument( '--anchors', type=str, help='path to anchor definitions, default ' + YOLO.get_defaults("anchors_path") ) parser.add_argument( '--classes', type=str, help='path to class definitions, default ' + YOLO.get_defaults("classes_path") ) parser.add_argument( '--gpu_num', type=int, help='Number of GPU to use, default ' + str(YOLO.get_defaults("gpu_num")) ) parser.add_argument( '--image', default=False, action="store_true", help='Image detection mode, will ignore all positional arguments' ) ''' Command line positional arguments -- for video detection mode ''' parser.add_argument( "--input", nargs='?', type=str,required=False,default='./video/video08.mp4', help = "Video input path" ) parser.add_argument( "--output", nargs='?', type=str, default="", help = "[Optional] Video output path" ) FLAGS = parser.parse_args() if FLAGS.image: """ Image detection mode, disregard any remaining command line arguments """ print("Image detection mode") if "input" in FLAGS: print(" Ignoring remaining command line arguments: " + FLAGS.input + "," + FLAGS.output)
[line77] detect_img(YOLO(**vars(FLAGS)))
elif "input" in FLAGS:
detect_video(YOLO(**vars(FLAGS)), FLAGS.input, FLAGS.output)
else:
print("Must specify at least video_input_path. See usage with --help.")
あなたの回答
tips
プレビュー