mae = 0 for i in tqdm(range(len(img_paths))): img = transform(Image.open(img_paths[i]).convert('RGB')).cuda() gt_file = h5py.File(img_paths[i].replace('.jpg','.h5').replace('images','ground-truth'),'r') groundtruth = np.asarray(gt_file['density']) output = model(img.unsqueeze(0)) mae += abs(output.detach().cpu().sum().numpy()-np.sum(groundtruth)) print (mae/len(img_paths))