-1

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:\Users\Gigabyte pc\Desktop\COUNTING\CSRNet-pytorch-master\UCF_CC_50\part_A_final/train_data\images\IMG_1.jpg

Shai
  • 111,146
  • 38
  • 238
  • 371
Akbar
  • 13
  • 6

2 Answers2

2

You are reading a matfile '...\ground_truth\GT_IMG_1.mat' corresponding to the image '...\IMG_1.jpg'. While you process this data point, you try to access variable 'image_info' stored in the matfile you read. As the error message you got states:

KeyError: 'image_info'

The matfile does not contain this variable, 'image_info'.

to debug, read the matfile and see what are the names of the variables stored there. Notice that naming them is case sensitive.

Shai
  • 111,146
  • 38
  • 238
  • 371
  • Actually I want to generate the ground truths values of 50 Images in UCF_CC_50 and read the mat files but could not found the variable name "image_info" – Akbar Jun 03 '21 at 15:41
  • The variable name here is IMG_1 for the first image in which just img is stored and having the dimension 409*614*3 unint8 – Akbar Jun 04 '21 at 08:50
  • @Akbar (a) please don't post code private in comments. (b) you need to change the dataset code to be compliant with the matfiles you want to read – Shai Jun 04 '21 at 09:03
  • How can I change the dataset code and what parameters need to change – Akbar Jun 04 '21 at 09:25
  • How may I change the dataset code and what parameter I need to change. thanks – Akbar Jun 04 '21 at 09:28
0

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)):
Bedir Yilmaz
  • 3,823
  • 5
  • 34
  • 54
  • Thank you so much for your Kind help and make me under stand that how to generate the ground truths. Respect for you – Akbar Jun 05 '21 at 06:05