示例#1
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)
示例#2
0
 def delete_requests(self, requests:list):
     """
     将requests列表中的request_image从data中删除
     @param: requests 需要删除的request图片的列表,注意列表中的每一项必须是request_path(because list.remove)
     @return: void 副作用,改变了self.data
     """
     print(f"Before deleting, {self.np}_data has requests: {self.total_requests}")
     print("There are {} requests should be deleted.".format(len(requests)))
     request2index = self.request2index()
     for request_path in requests:
         request_name = osp.basename(request_path)
         index = request2index[request_name]
         self.data['images'][index]["request_images"].remove(request_path)
     self.total_requests = ParseNP.total_requests(self.data)
     print(f"After deleting, {self.np}_data has requests: {self.total_requests}")
示例#3
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}")
示例#4
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}")
示例#5
0
 def show_info(self) -> dict:
     ParseNP.show_info(self.data,np=self.np)
示例#6
0
 def register_name2path(self) -> dict:
     return ParseNP.get_name2path(self.data, "register")
示例#7
0
 def request_name2path(self) -> dict:
     return ParseNP.get_name2path(self.data, "request")
示例#8
0
 def ids2index(self) -> dict:
     return ParseNP.get_ids2index(self.data)
示例#9
0
 def ids2sample(self) -> dict:
     return ParseNP.get_ids2sample(self.data)
示例#10
0
 def register2index(self) -> dict:
     return ParseNP.get_register2index(self.data)
示例#11
0
 def register2sample(self) -> dict:
     return ParseNP.get_register2sample(self.data)
示例#12
0
 def request2index(self) -> dict:
     return ParseNP.get_request2index(self.data)
示例#13
0
 def request2sample(self) -> dict:
     return ParseNP.get_request2sample(self.data)