I want to train the CSRNet model on UCF_CC_50 dataset but occurring this problem
JavaScriptx91KeyError Traceback (most recent call last) <ipython-input-11-78e054690de5> in <module>
24 img= plt.imread(img_path)
35 k = np.zeros((img.shape[0],img.shape[1]))
4***----> 6 gt = mat["image_info"][0,0][0,0][0]***
57 for i in range(0,len(gt)):
68 if int(gt[i][1])<img.shape[0] and int(gt[i][0])<img.shape[1]:
7
8**KeyError: 'image_info'**
9
JavaScript
1
17
17
1
----------
2
3
enter for img_path in img_paths:
4
print (img_path)
5
mat = io.loadmat(img_path.replace('.jpg','.mat').replace('images','ground_truth').replace('IMG_','GT_IMG_'))
6
img= plt.imread(img_path)
7
k = np.zeros((img.shape[0],img.shape[1]))
8
gt = mat["image_info"][0,0][0,0][0]
9
for i in range(0,len(gt)):
10
if int(gt[i][1])<img.shape[0] and int(gt[i][0])<img.shape[1]:
11
k[int(gt[i][1]),int(gt[i][0])]=1
12
k = gaussian_filter_density(k)
13
with h5py.File(img_path.replace('.jpg','.h5').replace('images','groundtruth'), 'w') as hf:
14
hf['density'] = kcode here
15
16
---------
17
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:
JavaScript
1
5
1
4 img= plt.imread(img_path)
2
5 k = np.zeros((img.shape[0],img.shape[1]))
3
6 gt = mat["annPoints"]
4
7 for i in range(0,len(gt)):
5