I want to train the CSRNet model on UCF_CC_50 dataset but occurring this problem
KeyError Traceback (most recent call last) <ipython-input-11-78e054690de5> in <module> 4 img= plt.imread(img_path) 5 k = np.zeros((img.shape[0],img.shape[1])) ***----> 6 gt = mat["image_info"][0,0][0,0][0]*** 7 for i in range(0,len(gt)): 8 if int(gt[i][1])<img.shape[0] and int(gt[i][0])<img.shape[1]: **KeyError: 'image_info'**
---------- enter 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','groundtruth'), 'w') as hf: hf['density'] = kcode here ---------
The file path is
C:UsersGigabyte pcDesktopCOUNTINGCSRNet-pytorch-masterUCF_CC_50part_A_final/train_dataimagesIMG_1.jpg
Advertisement
Answer
Your code does not comply with the structure of the annotation file you are trying to read. Annotations in UCF-50 CC dataset can simply be read by getting the values of the key “annPoints”.
You could apply the following changes to your code to read the x and y coordinates of pointwise human-head annotations:
4 img= plt.imread(img_path) 5 k = np.zeros((img.shape[0],img.shape[1])) 6 gt = mat["annPoints"] 7 for i in range(0,len(gt)):