Пример #1
0
 def delete_samples(self, samples:list):
     """
     将samples列表中的sample从data中删除
     @param: samples:list 需要删除的samples列表
     @return: void Side-effect: self.data
     """
     print(f"Before deleting, {self.np}_data has samples: {self.total_samples}")
     # BUG Cannot use set
     # dele_set = set(samples)
     dele_set = samples
     print("There are {} samples should be deleted".format(len(dele_set)))
     for sample in dele_set:
         self.data["images"].remove(sample)
     self.total_samples = ParseNP.total_samples(self.data)
     print(f"After deleting, {self.np}_data has samples: {self.total_samples}")
Пример #2
0
 def __init__(self, jsonfile, np:str):
     """
     对象化np_samples.json
     @param: jsonfile 可以是json的地址,或解析后的dict
     @param: np 是n_samples.json就填”n“,反之填”p“
     """
     if isinstance(jsonfile,str):
         self.data = ParseNP.read_json(jsonfile)
     elif isinstance(jsonfile,dict):
         self.data = jsonfile
     else:
         print("Unsupported sample file type: ",jsonfile)
     self.np = np
     self.group_id = self.data["images"][0]["group_id"]
     self.total_samples = ParseNP.total_samples(self.data)
     self.total_requests = ParseNP.total_requests(self.data)
     self.total_registers = ParseNP.total_registers(self.data)
Пример #3
0
 def delete_samples_by_registers(self,registers:list):
     """
     将包含registers的sample从data中删除
     @param: registers:list 需要删除的register图片的列表,注意列表中的每一项必须是register_path(because list.remove)
     @return: void 副作用,改变了self.data
     """
     print(f"Before deleting, {self.np}_data has samples: {self.total_samples}")
     register2sample = self.register2sample()
     dele_sample_list = []
     for register_path in registers:
         register_name = osp.basename(register_path)
         sample = register2sample[register_name]
         dele_sample_list.append(sample)
     # BUG Cannot use set()
     # dele_set = set(dele_sample_list) 
     dele_set = dele_sample_list
     print("There are {} samples should be deleted".format(len(dele_set)))
     for sample in dele_set:
         self.data["images"].remove(sample)
     self.total_samples = ParseNP.total_samples(self.data)
     print(f"After deleting, {self.np}_data has samples: {self.total_samples}")