def __getitem__(self, idx): hand_joints = self.get_hand_joints(idx) hand_root, hand_joints_rel = self.conv_hand_joints_to_rel(hand_joints) if self.fpa_subj_split: hand_obj_pose = hand_joints_rel else: obj_pose_rel = self.get_obj_pose(idx) obj_pose_rel[0:3] = obj_pose_rel[0:3] - hand_root hand_obj_pose = np.concatenate((hand_joints_rel, obj_pose_rel), 0) hand_obj_pose = torch.from_numpy(hand_obj_pose).float() subpath, file_num = self.get_subpath_and_file_num(idx) depth_img_numpy = self.read_depth_img(subpath, file_num) cropped_depth_img, crop_coords = self.get_cropped_depth_img( depth_img_numpy, hand_joints) cropped_depth_img = io_image.change_res_image(cropped_depth_img, new_res=(200, 200)) depth_img_torch = self.conv_depth_img_with_torch_transform( cropped_depth_img, self.transform_depth) if self.type == "train": return depth_img_torch, hand_obj_pose else: return depth_img_torch, hand_obj_pose, hand_root
def __getitem__(self, idx): pose = genfromtxt(self.pose_filepaths[self.file_idxs[idx]], delimiter=',')[1:] pose = torch.from_numpy(pose).float() colour = io_image.read_RGB_image( self.colour_filepaths[self.file_idxs[idx]]) mask = io_image.read_RGB_image( self.mask_filepaths[self.file_idxs[idx]]) cropped_img = self.crop_image(colour, mask) colour = io_image.change_res_image(colour, self.img_res) mask = io_image.change_res_image(mask, self.img_res) cropped_img = io_image.change_res_image(cropped_img, self.img_res) with_imagenet = io_image.read_RGB_image( self.with_imagenet_filepaths[self.file_idxs[idx]], new_res=self.img_res) data_image = with_imagenet if (not self.noise_channel) and self.num_channels > 3: depth = io_image.read_RGB_image( self.depth_filepaths[self.file_idxs[idx]], new_res=self.img_res) depth = np.reshape(depth, (depth.shape[0], depth.shape[1], 1)) data_image = np.concatenate((data_image, depth), axis=-1).astype(float) #cropped_img_non_noisy = np.copy(cropped_img) #cropped_img_noisy, noise_idxs = util.add_noise(cropped_img, 0.2) data_image_noisy, noise_idxs = util.add_noise(data_image, self.noise_level) #colour = np.concatenate((colour, noise_idxs), axis=-1).astype(float) if self.transform: data_image_noisy = self.transform(data_image_noisy).float() noise_idxs = self.transform(noise_idxs).float() #cropped_img_noisy = self.transform(cropped_img_noisy) #cropped_img_non_noisy = self.transform(cropped_img_non_noisy) colour = self.transform(colour).float() data_image_noisy = torch.cat((data_image_noisy, noise_idxs), 0) #vis.plot_image((data_image_noisy.numpy()[0:3, :, :] + 0.5) * 255) #vis.show() #vis.plot_image((colour.numpy() + 0.5) * 255) #vis.show() return data_image_noisy, colour
def __getitem__(self, idx): #idx = 16 # Read images subpath, file_num = self.get_subpath_and_file_num(idx) rgb_img = self.read_rgb_img(subpath, file_num) #gen_obj_rgb_img = self.read_gen_obj_rgb_img(subpath, file_num) # Transform images for pytorch rgb_img = io_image.change_res_image(rgb_img, self.params_dict['img_res']) rgb_img = self.transform(rgb_img) #gen_obj_rgb_img = io_image.change_res_image(gen_obj_rgb_img, # self.params_dict['img_res']) #gen_obj_rgb_img = self.transform(gen_obj_rgb_img) return (rgb_img, rgb_img)
def __getitem__(self, idx): hand_joints = self.get_hand_joints(idx) hand_root, hand_joints_rel = self.conv_hand_joints_to_rel(hand_joints) if self.fpa_subj_split: hand_obj_pose = hand_joints_rel else: obj_pose_rel = self.get_obj_pose(idx) obj_pose_rel[0:3] = obj_pose_rel[0:3] - hand_root hand_obj_pose = np.concatenate((hand_joints_rel, obj_pose_rel), 0) hand_obj_pose = torch.from_numpy(hand_obj_pose).float() subpath, file_num = self.get_subpath_and_file_num(idx) depth_img_numpy = self.read_depth_img(subpath, file_num) cropped_depth_img, crop_coords = self.get_cropped_depth_img( depth_img_numpy, hand_joints) cropped_depth_img = io_image.change_res_image(cropped_depth_img, new_res=(200, 200)) # read reconstructed image img_recon_path = self.root_folder + self.gen_folder +\ subpath + str(int(file_num)) + '_recon.npy' depth_img_final = np.zeros((200, 200, 2)) recon = True try: depth_img_recon = np.load(img_recon_path) #vis.plot_image(depth_img_recon) #vis.show() #vis.plot_image(cropped_depth_img) #vis.show() depth_img_final[:, :, 0] = cropped_depth_img depth_img_final[:, :, 1] = depth_img_recon except: depth_img_final[:, :, 1] = cropped_depth_img depth_img_torch = self.conv_depth_img_with_torch_transform( depth_img_final, self.transform_depth, recon=recon) if self.type == "train": return depth_img_torch, hand_obj_pose else: return depth_img_torch, hand_obj_pose, hand_root
loss = my_losses.calculate_loss_HALNet( loss_func, output, label_heatmaps, model.joint_ixs, model.WEIGHT_LOSS_INTERMED1, model.WEIGHT_LOSS_INTERMED2, model.WEIGHT_LOSS_INTERMED3, model.WEIGHT_LOSS_MAIN, train_vars['iter_size']) loss_pixel, label_bbox, out_bbox = calculate_pixel_loss( output[3].detach().cpu().numpy()[0, :, :, :], label_heatmaps) losses_pixel.append(loss_pixel) if batch_idx == 4: depth_img = data.cpu().numpy()[0, 0, :, :] depth_img_crop = depth_img[label_bbox[0, 0]:label_bbox[1, 0], label_bbox[0, 1]:label_bbox[1, 1]] depth_img_crop = io_image.change_res_image(depth_img_crop, ((200, 200))) vis.plot_image(depth_img_crop, title=train_loader.dataset.get_img_title(batch_idx)) vis.show() fig = vis.plot_image( depth_img, title=train_loader.dataset.get_img_title(batch_idx)) #vis.plot_bound_box(label_bbox, fig=fig, color='blue') #vis.plot_bound_box(out_bbox, fig=fig, color='red') vis.show() a = 0 train_vars['total_loss'] = loss.item() print('Batch {} / {}'.format(batch_idx, len_dataset)) print('Loss (pixel): {}'.format(loss_pixel))