def _remove_small_objects(self, items): filtered_item = [] for item in items: m = np.array(Image.open(item['mask_path'])) if util.change_coordinates(m, 8.0, 0.0).sum() > 2: ##相当于对mask进行下采样到32倍,下采样后的大小变为(13, 17),然后判断下采样的图片的像素值之和是否大于2 filtered_item.append(item) # 将大于2的图片放入filtered_item中,删掉小的图片 return filtered_item # 365个
def _remove_small_objects(self, items): filtered_item = [] for item in items: mask = item.read_mask() if util.change_coordinates(mask, 32.0, 0.0).sum() > 2: filtered_item.append(item) return filtered_item
def _remove_small_objects(self, items): filtered_item = [] for item in items: mask = item.read_mask() #(366, 500) if util.change_coordinates(mask, 32.0, 0.0).sum( ) > 2: ##相当于对mask进行下采样到32倍,下采样后的大小变为(13, 17),然后判断下采样的图片的像素值之和是否大于2 filtered_item.append(item) #将大于2的图片放入filtered_item中,删掉小的图片 return filtered_item #365个
def _remove_small_objects(self, items): ''' 移除一些目标较小的目标 :param items: 以DBPascalItem为数据格式list :return: 移除小目标后的list, 元素任然是DBPascalItem ''' filtered_item = [] for item in items: mask = item.read_mask() if util.change_coordinates(mask, 32.0, 0.0).sum() > 2: filtered_item.append(item) return filtered_item
def load_frame(self, player, first_index, second_index): cprint( 'Loading pair = ' + player.name + ', ' + str(first_index) + ', ' + str(second_index), bcolors.WARNING) if second_index in first_index: return None images1 = [] labels1 = [] image_path = [] shape1 = self.first_shape for ind in first_index: frame1_dict = player.get_frame(ind) image1, label1, shape1 = self.__prepross(frame1_dict, shape1) images1.append(image1.transpose((2, 0, 1))) labels1.append(label1) image_path.append(frame1_dict['image_path']) item = dict(first_img=images1, image1_path=image_path) if second_index is not None: frame2_dict = player.get_frame(second_index) image2, label2, shape = self.__prepross(frame2_dict, self.second_shape) item['second_img'] = [image2.transpose((2, 0, 1))] item['image2_path'] = [ frame2_dict['image_path'], ] if self.deploy_mode: first_semantic_labels = [] first_mask_orig = [] first_img_orig = [] for ind in first_index: a, b, c = self.__get_deploy_info(player, ind) first_semantic_labels.append(a) first_mask_orig.append(b) first_img_orig.append(c) deploy_info = dict(seq_name=player.name, first_index=first_index, first_img_orig=first_img_orig, first_mask_orig=first_mask_orig, first_semantic_labels=first_semantic_labels) if second_index is not None: second_semantic_labels, second_mask_orig, second_img_orig = self.__get_deploy_info( player, second_index) deploy_info.update( second_index=second_index, second_img_orig=second_img_orig, second_mask_orig=second_mask_orig, second_semantic_labels=second_semantic_labels) item['deploy_info'] = deploy_info #create first_labels for i in range(len(self.first_label_params)): name, down_scale, offset = self.first_label_params[i] item[name] = [] for label1 in labels1: nlabel1 = util.change_coordinates(label1, down_scale, offset) nlabel1 = (nlabel1 - self.first_label_mean) * self.first_label_scale assert (self.__is_integer(nlabel1)) item[name].append(nlabel1.reshape((1, ) + nlabel1.shape)) if second_index is not None: #create second_labels for i in range(len(self.second_label_params)): name, down_scale, offset = self.second_label_params[i] nlabel2 = util.change_coordinates(label2, down_scale, offset) assert (self.__is_integer(nlabel2)) item[name] = [nlabel2.reshape((1, ) + nlabel2.shape)] if self.has_cont: item['cont'] = [0] + [1] * (len(first_index) - 1) return item
def load_frame(self, player1, player2, first_index_1, first_index_2, second_index): # cprint('Loading pair = ' + player.name + ', ' + str(first_index) + ', ' + str(second_index), bcolors.WARNING) # if second_index in first_index: # return None images1 = [] labels1 = [] image_path_1 = [] images2 = [] labels2 = [] image_path_2 = [] shape1 = self.first_shape for ind1, ind2 in zip(first_index_1, first_index_2): frame1_dict_1 = player1.get_frame(ind1) frame1_dict_2 = player2.get_frame(ind2) image1, label1, shape1 = self.__prepross(frame1_dict_1, shape1) image2, label2, shape1 = self.__prepross(frame1_dict_2, shape1) images1.append(image1.transpose((2, 0, 1))) images2.append(image2.transpose((2, 0, 1))) labels1.append(label1) labels2.append(label2) image_path_1.append(frame1_dict_1['image_path']) image_path_2.append(frame1_dict_2['image_path']) item = dict(first_img=[images1, images2], image1_path=[image_path_1, image_path_2]) if second_index is not None: frame2_dict = player1.get_frame(second_index) image_q, label_q, shape = self.__prepross(frame2_dict, self.second_shape) item['second_img'] = [image_q.transpose((2, 0, 1))] item['image2_path'] = [ frame2_dict['image_path'], ] if self.deploy_mode: # first_semantic_labels=[] # first_mask_orig=[] # first_img_orig=[] # for ind in first_index: # a,b,c = self.__get_deploy_info(player, ind) # first_semantic_labels.append(a) # first_mask_orig.append(b) # first_img_orig.append(c) # # deploy_info = dict(seq_name=player.name, # first_index=first_index, # first_img_orig=first_img_orig, # first_mask_orig=first_mask_orig, # first_semantic_labels=first_semantic_labels) deploy_info = {} if second_index is not None: second_semantic_labels, second_mask_orig, second_img_orig = self.__get_deploy_info( player1, second_index) deploy_info.update( second_index=second_index, second_img_orig=second_img_orig, second_mask_orig=second_mask_orig, second_semantic_labels=second_semantic_labels) item['deploy_info'] = deploy_info # create first_labels for i in range(len(self.first_label_params)): name, down_scale, offset = self.first_label_params[i] item[name] = [] class_one = [] class_two = [] for label1 in labels1: nlabel1 = util.change_coordinates(label1, down_scale, offset) nlabel1 = (nlabel1 - self.first_label_mean) * self.first_label_scale class_one.append(nlabel1.reshape((1, ) + nlabel1.shape)) item[name].append(class_one) for label2 in labels2: assert (self.__is_integer(nlabel1)) nlabel2 = util.change_coordinates(label2, down_scale, offset) nlabel2 = (nlabel2 - self.first_label_mean) * self.first_label_scale assert (self.__is_integer(nlabel2)) class_two.append(nlabel2.reshape((1, ) + nlabel2.shape)) item[name].append(class_two) if second_index is not None: # create second_labels for i in range(len(self.second_label_params)): name, down_scale, offset = self.second_label_params[i] nlabel_q = util.change_coordinates(label_q, down_scale, offset) assert (self.__is_integer(nlabel_q)) item[name] = [nlabel_q.reshape((1, ) + nlabel_q.shape)] # if self.has_cont: # item['cont'] = [0] + [1] * (len(first_index) - 1) return item