测试用于对象检测的Svm模型时出现错误

时间:2019-10-17 12:01:33

标签: machine-learning computer-vision anaconda jupyter svm

from skimage.transform import pyramid_gaussian
from sklearn.externals import joblib
from skimage import color
from skimage import io
from imutils.object_detection import non_max_suppression
import imutils
import numpy as np
import cv2
import os
import glob 


orientations = 9
pixels_per_cell = (8, 8)
cells_per_block = (2, 2)
threshold = .3


def sliding_window(image, stepSize, windowSize):
    for y in range(0, image.shape[0], stepSize):
        for x in range(0, image.shape[1], stepSize):
            yield (x, y, image[y: y + windowSize[1], x:x + windowSize[0]])

 model = joblib.load('model_name.npy')

scale = 0
detections = []

img= cv2.imread("pos\56_resized.jpg")


(winW, winH)= (180,320)
windowSize=(winW,winH)
downscale=1.5
for resized in pyramid_gaussian(img, downscale=1.5):
    for (x,y,window) in sliding_window(resized, stepSize=10, windowSize=(winW,winH)):
        if window.shape[0] != winH or window.shape[1] !=winW:
            continue
        window=color.rgb2gray(window)
        fds = hog(window, orientations, pixels_per_cell, cells_per_block, block_norm='L2')
        fds = fds.reshape(1, -1)
        pred = model.predict(fds)

        if pred == 1:
            if model.decision_function(fds) > 0.6:
                print("Detection:: Location -> ({}, {})".format(x, y))
                print("Scale ->  {} | Confidence Score {} \n".format(scale,model.decision_function(fds)))
                detections.append((int(x*(downscale**scale)),int(y*(downscale**scale)),model.decision_function(fds),int(windowSize[0]*(downscale**scale)),int(windowSize[1]*(downscale**scale))
    scale+=1
  

** ValueError追溯(最近一次通话最后一次)   ---->金字塔1中img1的img1(img,downscale = 2):         滑动窗口中的(x,y,window)(调整大小,stepSize = 10,windowSize =(winW,winH))中的2:         3,如果window.shape [0]!= winH或window.shape [1]!= winW:         4继续         5 window = color.rgb2gray(window)

     

D:\ Anaconda3 \ lib \ site-packages \ skimage \ transform \ pyramids.py在   pyramid_gaussian(图像,max_layer,缩小比例,sigma,顺序,模式,   cval,多通道)       195       196#强制浮动以在金字塔中保持一致的数据类型   -> 197图片= img_as_float(图片)       198       199层= 0

     

D:\ Anaconda3 \ lib \ site-packages \ skimage \ util \ dtype.py在   img_as_float(image,force_copy)       411       412“”“   -> 413 return convert(image,np.floating,force_copy)       414       415

     

D:\ Anaconda3 \ lib \ site-packages \ skimage \ util \ dtype.py in convert(image,   dtype,force_copy,uniform)       124(如果不是)(_ supported_types中的dtype_in和_supported_types中的dtype_out):       125引发ValueError(“无法从{}转换为{}。”   -> 126 .format(dtypeobj_in,dtypeobj_out))       127       128 def sign_loss():

     

ValueError:无法从对象转换为float64。

     

**

0 个答案:

没有答案