def __getitem__(self, idx): ######################################################################## # TODO: # # Return the idx sample in the Dataset. A simple should be a dictionary# # where the key, value should be like # # {'image': image of shape [C, H, W], # # 'keypoints': keypoints of shape [num_keypoints, 2]} # ######################################################################## image = get_image(idx, self.key_pts_frame) img_shape = image.shape image = image.reshape(1, img_shape[0], img_shape[1]) keypoints = get_keypoints(idx, self.key_pts_frame) sample = {'image': image, 'keypoints': keypoints} ######################################################################## # END OF YOUR CODE # ######################################################################## if self.transform: sample = self.transform(sample) return sample
def __getitem__(self, idx): ######################################################################## # TODO: # # Return the idx sample in the Dataset. A simple should be a dictionary# # where the key, value should be like # # {'image': image of shape [C, H, W], # # 'keypoints': keypoints of shape [num_keypoints, 2]} # ######################################################################## image = get_image(idx, self.key_pts_frame) rows, columns = image.shape image = image.reshape(1, rows, columns) keypoints = self.key_pts_frame.iloc[ idx, self.key_pts_frame.columns != 'Image'] keypoints = np.array([keypoints]) keypoints = keypoints.astype('float').reshape(-1, 2) sample = {'image': image, 'keypoints': keypoints} ######################################################################## # END OF YOUR CODE # ######################################################################## if self.transform: sample = self.transform(sample) return sample
def __getitem__(self, idx, verbose=False): sample = {'image': None, 'keypoints': None} ####################################################################### # TODO: # # Return the idx sample in the Dataset. A sample should be a # # dictionary where the key, value should be like # # {'image': image of shape [C, H, W], # # 'keypoints': keypoints of shape [num_keypoints, 2]} # ####################################################################### image = get_image(idx, self.key_pts_frame) image = image[np.newaxis, :] landmarks = get_keypoints(idx, self.key_pts_frame) if verbose: print("-------------------------") print("Dataloader") print("idx: " + str(idx)) print("img shape: " + str(image.shape)) print("landmarks: " + str(landmarks.shape)) print(landmarks) print("-------------------------") sample = {'image': image, 'keypoints': landmarks} ####################################################################### # END OF YOUR CODE # ####################################################################### if self.transform: sample = self.transform(sample) return sample
def __getitem__(self, idx): sample = {'image': None, 'keypoints': None} ####################################################################### # TODO: # # Return the idx sample in the Dataset. A sample should be a # # dictionary where the key, value should be like # # {'image': image of shape [C, H, W], # # 'keypoints': keypoints of shape [num_keypoints, 2]} # ####################################################################### from exercise_code.data_utils import get_keypoints from exercise_code.data_utils import get_image # sample['image'] = np.array([get_image(idx, self.key_pts_frame)]) # from (96, 96) to (1, 96, 96) sample['image'] = get_image(idx, self.key_pts_frame)[np.newaxis, :] sample['keypoints'] = get_keypoints(idx, self.key_pts_frame) ####################################################################### # END OF YOUR CODE # ####################################################################### if self.transform: sample = self.transform(sample) return sample
def __getitem__(self, idx): ######################################################################## # TODO: # # Return the idx sample in the Dataset. A simple should be a dictionary# # where the key, value should be like # # {'image': image of shape [C, H, W], # # 'keypoints': keypoints of shape [num_keypoints, 2]} # # You can use mpimg.imread(image path) to read out image data # ######################################################################## from exercise_code.data_utils import get_keypoints from exercise_code.data_utils import get_image sample = {} sample['image'] = np.array([get_image(idx, self.key_pts_frame)]) sample['keypoints'] = get_keypoints(idx, self.key_pts_frame) ######################################################################## # END OF YOUR CODE # ######################################################################## if self.transform: sample = self.transform(sample) return sample
def __getitem__(self, idx): ######################################################################## # TODO: # # Return the idx sample in the Dataset. A simple should be a dictionary# # where the key, value should be like # # {'image': image of shape [C, H, W], # # 'keypoints': keypoints of shape [num_keypoints, 2]} # # You can use mpimg.imread(image path) to read out image data # ######################################################################## sample = { 'image': np.expand_dims(get_image(idx, self.key_pts_frame), 0), 'keypoints': get_keypoints(idx, self.key_pts_frame) } ######################################################################## # END OF YOUR CODE # ######################################################################## if self.transform: sample = self.transform(sample) return sample
def __getitem__(self, idx): sample = {'image': None, 'keypoints': None} ####################################################################### # TODO: # # Return the idx sample in the Dataset. A sample should be a # # dictionary where the key, value should be like # # {'image': image of shape [C, H, W], # # 'keypoints': keypoints of shape [num_keypoints, 2]} # ####################################################################### image = np.array([get_image(idx, self.key_pts_frame)]) keypoints = get_keypoints(idx, self.key_pts_frame) sample = {'image': image, 'keypoints': keypoints} ####################################################################### # END OF YOUR CODE # ####################################################################### if self.transform: sample = self.transform(sample) return sample
def __getitem__(self, idx): sample = {'image': None, 'keypoints': None} ####################################################################### # TODO: # # Return the idx sample in the Dataset. A sample should be a # # dictionary where the key, value should be like # # {'image': image of shape [C, H, W], # # 'keypoints': keypoints of shape [num_keypoints, 2]} # ####################################################################### from exercise_code.data_utils import get_keypoints, get_image sample = {} sample["image"] = get_image(idx, self.key_pts_frame).reshape(-1, 96, 96) sample["keypoints"] = get_keypoints(idx, self.key_pts_frame) ####################################################################### # END OF YOUR CODE # ####################################################################### if self.transform: sample = self.transform(sample) return sample
def __getitem__(self, idx): ######################################################################## # TODO: # # Return the idx sample in the Dataset. A simple should be a dictionary# # where the key, value should be like # # {'image': image of shape [C, H, W], # # 'keypoints': keypoints of shape [num_Normalize()keypoints, 2]} # # You can use mpimg.imread(image path) to read out image data # ######################################################################## #self.key_pts_frame map = {} image = get_image(idx, self.key_pts_frame) image = np.array(image) image = np.reshape(image, (1, image.shape[0], image.shape[1])) key_pts = get_keypoints(idx, self.key_pts_frame) map['image'] = image map['keypoints'] = np.float_(key_pts) t = self.transform if (t is not None): map = t(map) return (map) pass ######################################################################## # END OF YOUR CODE # ######################################################################## if self.transform: sample = self.transform(sample) return sample
# In[ ]: key_pts_frame.dropna(inplace=True) key_pts_frame.describe().loc['count'].plot.bar() print(key_pts_frame.shape) # In[ ]: from exercise_code.data_utils import get_keypoints from exercise_code.data_utils import get_image n = 0 image = get_image(n, key_pts_frame) keypoints = get_keypoints(n, key_pts_frame) print('image size: {}'.format(image.shape)) print('keypoints size: {}'.format(keypoints.shape)) # Below, is a function `show_all_keypoints` that takes in an image and keypoints and displays them. As you look at this data, **note that these images are not all of the same quality**! # In[ ]: # select an image by index in our data frame for n in range(5): image = get_image(n, key_pts_frame) key_pts = get_keypoints(n, key_pts_frame) show_all_keypoints(image, key_pts)