如何在Tensornet中使用yolov3?

问题描述

请帮助我解决以下问题,我计划在较高级别使用yolov3来检测图像中的物体(车辆,行人)。我遇到了库张量网。由于可以直接使用几行代码,因此我想尝试一下,但是由于代码在 行:

Boxes = model.get_Boxes(preds,imge.shape[1:3])

我得到的错误

enter image description here

解决此问题方面的任何帮助将不胜感激

下面是我的完整代码

import tensorflow as tf
import tensornets as nets
import cv2
import numpy as np
import time

inputs = tf.placeholder(tf.float32,[None,416,3]) 
model = nets.YOlov3COCO(inputs,nets.Darknet19)

classes={'0':'person','1':'bicycle','2':'car','3':'bike','5':'bus','7':'truck'}
list_of_classes=[0,1,2,3,5,7]#to display other detected #objects,change the classes and list of classes to their respective #COCO indices available in their website. Here 0th index is for #people and 1 for bicycle and so on. If you want to detect all the #classes,add the indices to this list

sess = tf.Session()
sess.run(model.pretrained())
#"D://pyworks//yolo//videoplayback.mp4"   
frame = cv2.imread("img.jpg")
img=cv2.resize(frame,(416,416))
imge=np.array(img).reshape(-1,3)
start_time=time.time()
preds = sess.run(model.preds,{inputs: model.preprocess(imge)})
print("--- %s seconds ---" % (time.time() - start_time)) 
Boxes = model.get_Boxes(preds,imge.shape[1:3])
cv2.namedWindow('image',cv2.WINDOW_norMAL)

cv2.resizeWindow('image',700,700)
#print("--- %s seconds ---" % (time.time() - start_time)) 
Boxes1=np.array(Boxes)
for j in list_of_classes:
    count =0
    if str(j) in classes:
        lab=classes[str(j)]
    if len(Boxes1) !=0:


        for i in range(len(Boxes1[j])):
            Box=Boxes1[j][i] 

            if Boxes1[j][i][4]>=.40:


                count += 1    

                cv2.rectangle(img,(Box[0],Box[1]),(Box[2],Box[3]),(0,255,0),1)
                cv2.putText(img,lab,cv2.FONT_HERShey_SIMPLEX,.5,255),lineType=cv2.LINE_AA)
    print(lab,": ",count)


cv2.imshow("image",img)  

我试图在Windows 10上的python虚拟环境中运行此代码,以下是具有该版本的库

absl-py (0.10.0)
argon2-cffi (20.1.0)
astor (0.8.1)
async-generator (1.10)
attrs (20.2.0)
backcall (0.2.0)
bleach (3.1.5)
cffi (1.14.2)
colorama (0.4.3)
Cython (0.29.21)
decorator (4.4.2)
defusedxml (0.6.0)
entrypoints (0.3)
gast (0.4.0)
google-pasta (0.2.0)
grpcio (1.32.0)
h5py (2.10.0)
importlib-Metadata (1.7.0)
ipykernel (5.3.4)
ipython (7.16.1)
ipython-genutils (0.2.0)
jedi (0.17.2)
Jinja2 (2.11.2)
jsonschema (3.2.0)
jupyter-client (6.1.7)
jupyter-core (4.6.3)
jupyterlab-pygments (0.1.1)
Keras-Applications (1.0.8)
Keras-Preprocessing (1.1.2)
Markdown (3.2.2)
MarkupSafe (1.1.1)
mistune (0.8.4)
nbclient (0.5.0)
nbconvert (6.0.1)
nbformat (5.0.7)
nest-asyncio (1.4.0)
notebook (6.1.4)
numpy (1.19.2)
opencv-python (4.4.0.42)
packaging (20.4)
pandocfilters (1.4.2)
parso (0.7.1)
pickleshare (0.7.5)
pip (9.0.3)
prometheus-client (0.8.0)
prompt-toolkit (3.0.7)
protobuf (3.13.0)
pycparser (2.20)
Pygments (2.6.1)
pyparsing (2.4.7)
pyrsistent (0.17.2)
python-dateutil (2.8.1)
pywin32 (228)
pywinpty (0.5.7)
pyzmq (19.0.2)
Send2Trash (1.5.0)
setuptools (39.0.1)
six (1.15.0)
tensorboard (1.14.0)
tensorflow (1.14.0)
tensorflow-estimator (1.14.0)
termcolor (1.1.0)
terminado (0.8.3)
testpath (0.4.4)
tornado (6.0.4)
traitlets (4.3.3)
wcwidth (0.2.5)
webencodings (0.5.1)
Werkzeug (1.0.1)
wheel (0.35.1)
wrapt (1.12.1)
zipp (3.1.0)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)