leeyeehoo / CSRNet-pytorch

CSRNet: Dilated Convolutional Neural Networks for Understanding the Highly Congested Scenes
656 stars 259 forks source link

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

Closed RickStor closed 5 years ago

RickStor commented 5 years ago

Hi, I have this issue:

When I try this code:

for img_path in img_paths:
    print (img_path)
    mat = io.loadmat(img_path.replace('.jpg','.mat').replace('images','ground-truth').replace('IMG_','GT_IMG_'))
    img= plt.imread(img_path)
    k = np.zeros((img.shape[0],img.shape[1]))
    gt = mat["image_info"][0,0][0,0][0]
    for i in range(0,len(gt)):
        if int(gt[i][1])<img.shape[0] and int(gt[i][0])<img.shape[1]:
            k[int(gt[i][1]),int(gt[i][0])]=1
    k = gaussian_filter_density(k)
    with h5py.File(img_path.replace('.jpg','.h5').replace('images','ground-truth'), 'w') as hf:
            hf['density'] = k

I got this error:

G:\Crowd_counting\CSRNet-pytorch-master\ShanghaiTech/part_A/train_data\images\IMG_1.jpg
(768, 1024)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-93-4a13f34beb91> in <module>
      8         if int(gt[i][1])<img.shape[0] and int(gt[i][0])<img.shape[1]:
      9             k[int(gt[i][1]),int(gt[i][0])]=1
---> 10     k = gaussian_filter_density(k)
     11     with h5py.File(img_path.replace('.jpg','.h5').replace('images','ground-truth'), 'w') as hf:
     12             hf['density'] = k

<ipython-input-82-dc4331d0e920> in gaussian_filter_density(gt)
     10     leafsize = 2048
     11     # build kdtree
---> 12     tree = scipy.spatial.KDTree(pts.copy(), leafsize=leafsize)
     13     # query kdtree
     14     distances, locations = tree.query(pts, k=4)

G:\Anaconda3\lib\site-packages\scipy\spatial\kdtree.py in __init__(self, data, leafsize)
    233     def __init__(self, data, leafsize=10):
    234         self.data = np.asarray(data)
--> 235         self.n, self.m = np.shape(self.data)
    236         self.leafsize = int(leafsize)
    237         if self.leafsize < 1:

ValueError: not enough values to unpack (expected 2, got 0)
RickStor commented 5 years ago

where is the error?

Akon-Fiber commented 4 years ago

do you get the anwser? I meet the same error now

shiv-u commented 4 years ago

@Akon-Fiber If you are using python3 make these changes. In ,b>make_dataset.ipynb inside gaussian_filter_density function change statement pts = np.array(zip(np.nonzero(gt)[1], np.nonzero(gt)[0])) to pts = np.array(list(zip(np.nonzero(gt)[1], np.nonzero(gt)[0])))

flavves commented 2 years ago

@Akon-Fiber If you are using python3 make these changes. In ,b>make_dataset.ipynb inside gaussian_filter_density function change statement pts = np.array(zip(np.nonzero(gt)[1], np.nonzero(gt)[0])) to pts = np.array(list(zip(np.nonzero(gt)[1], np.nonzero(gt)[0])))

wow thanks man ı can fix right now