Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

computer vision - Object Detection Python3: ValueError: not enough values to unpack (expected 2, got 0)

Using SSD for Object Detection but faced with a error

Code:

# Importing the libraries
import torch
from torch.autograd import Variable
import cv2
from data import BaseTransform, VOC_CLASSES as labelmap
from ssd import build_ssd
import imageio


# Defining a function that will do the detections
def detect(frame, net, transform):
height, width = frame.shape[:2]
frame_t = transform(frame)[0]
x = torch.from_numpy(frame_t).permute(2, 0, 1)
x = Variable(x.unsqueeze(0))
y = net(x)
detections = y.data
scale = torch.Tensor([width, height, width, height])
# detections = [batch, number of classes, number of occurence, (score, x0, Y0, x1, y1)]
for i in range(detections.size(1)):
    j = 0
    while detections[0, i, j, 0] >= 0.6:
        pt = (detections[0, i, j, 1:] * scale).numpy()
        cv2.rectangle(frame, (int(pt[0]), int(pt[1])), (int(pt[2]), int(pt[3])), (255, 0, 0), 2)
        cv2.putText(frame, labelmap[i - 1], (int(pt[0]), int(pt[1])), cv2.FONT_HERSHEY_SIMPLEX, 2, 
         (255, 255, 255), 2, cv2.LINE_AA)
        j += 1
return frame

# Creating the SSD neural network
net = build_ssd('test')
net.load_state_dict(torch.load('ssd300_mAP_77.43_v2.pth', map_location = lambda storage, loc: 
storage))

# Creating the transformation
transform = BaseTransform(net.size, (104/256.0, 117/256.0, 123/256.0))

# Doing some Object Detection on a video
reader = imageio.get_reader('funny_dog.mp4')
fps = reader.get_meta_data()['fps']
writer = imageio.get_writer('output.mp4', fps = fps)
for i, frame in enumerate(reader):
  frame = detect(frame, net.eval(), transform)
  writer.append_data(frame)
  print(i)
writer.close()

Error:

ValueError: not enough values to unpack (expected 2, got 0)

Error Popup:

runcell(0, 'D:/Personal/Computer Vision/P23-Computer-Vision-AZ-Template- Folder/Computer_Vision_A_Z_Template_Folder/Module 2 - Object Detection/P23-Code-for-Windows/Code for Windows/object_detection_commented.py') Traceback (most recent call last):

File "D:PersonalComputer VisionP23-Computer-Vision-AZ-Template- FolderComputer_Vision_A_Z_Template_FolderModule 2 - Object DetectionP23-Code-for-WindowsCode for Windowsobject_detection_commented.py", line 41, in frame = detect(frame, net.eval(), transform)

File "D:PersonalComputer VisionP23-Computer-Vision-AZ-Template- FolderComputer_Vision_A_Z_Template_FolderModule 2 - Object DetectionP23-Code-for-WindowsCode for Windowsobject_detection_commented.py", line 17, in detect y = net(x) # We feed the neural network ssd with the image and we get the output y.

File "C:Userssurajanaconda3libsite-packagesorch nmodulesmodule.py", line 532, in call result = self.forward(*input, **kwargs)

File "D:PersonalComputer VisionP23-Computer-Vision-AZ-Template- FolderComputer_Vision_A_Z_Template_FolderModule 2 - Object DetectionP23-Code-for-WindowsCode for Windowsssd.py", line 98, in forward output = self.detect(

File "D:PersonalComputer VisionP23-Computer-Vision-AZ-Template- FolderComputer_Vision_A_Z_Template_FolderModule 2 - Object DetectionP23-Code-for-WindowsCode for Windowslayersfunctionsdetection.py", line 63, in forward ids, count = nms(boxes, scores, self.nms_thresh, self.top_k)

New to this so couldn't find the mistake. Help will be most appreciated.

question from:https://stackoverflow.com/questions/65671994/object-detection-python3-valueerror-not-enough-values-to-unpack-expected-2-g

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...