예제 #1
0
 def take_action(self,action_index):
     self.action_trajectory.append(action_index)
     result = take_action(self.current_image,action_index)
     new_l2_distance = compute_color_l2(current_image=result, target_image=self.target_image)
     reward = self.l2_distance_old - new_l2_distance
     self.current_image = result
     if new_l2_distance < TERMINAL_THRESHOLD:
         self.done = True
     return result,reward,self.done
예제 #2
0
 def reset(self):
     raw_img_path = random.choice(self.raw_path)
     raw_img_name = os.path.basename(raw_img_path)
     raw_img_index = raw_img_name.split('_')[0]
     self.raw_image = load_image(raw_img_path)
     self.target_image = load_image( self.target_path+"%s.jpg"%raw_img_index) # 干净的目标图像
     self.current_image = self.raw_image
     self.l2_distance_old = compute_color_l2(current_image=self.current_image,target_image=self.target_image)
     self.action_trajectory = []
     self.done = False
     return self.current_image
예제 #3
0
 def take_master_action(self, action_index):
     self.action_trajectory.append(self.master_action_list[action_index])
     result = self.master_action_list[action_index](self.current_image)
     new_l2_distance = compute_color_l2(current_image=result, target_image=self.target_image)
     reward = self.l2_distance_old - new_l2_distance
     self.l2_distance_old = new_l2_distance
     self.current_image = result
     #print("master_distance: ",new_l2_distance)
     if new_l2_distance < TERMINAL_THRESHOLD:
         self.done = True
     # result = np.clip(result*255.0,a_min=0.0,a_max=255.0).astype(np.uint8)
     return result,self.get_color_feature(result),self.get_gray_feature(result),reward,self.done
    def take_action(self,action_index,policy_index):
        result = self.sub_policy_list[policy_index][action_index](self.current_image)

        new_l2_distance = compute_color_l2(current_image=result, target_image=self.target_image)
        reward = self.l2_distance_old - new_l2_distance

        self.l2_distance_old = new_l2_distance
        self.distance = new_l2_distance

        self.current_image = result
        if new_l2_distance < TERMINAL_THRESHOLD:
            self.done = True
        # result = np.clip(result*255.0,a_min=0.0,a_max=255.0).astype(np.uint8)
        return result,self.get_color_feature(result),self.get_gray_feature(result),reward,self.done
 def reset(self):
     target_name = random.choice(self.target_name_list)
     self.img_name = target_name
     index_str = target_name[0:target_name.find('.')]
     for name in self.dirty_name_list:
         index = name[0:name.find('_')]
         if index == index_str:
             dirty_name = index
             break
     dirty_name = dirty_name+"_a.jpg"
     # print("dirty_name:%s  target_name:%s"%(dirty_name,target_name ))
     # print("dirty_path:%s  target_path:%s"%(self.dirty_path,self.target_path ))
     self.dirty_image = load_image2numpy(self.dirty_path+dirty_name) # 脏数据
     self.target_image = load_image2numpy(self.target_path+target_name) # 干净数据
     self.current_image = self.dirty_image
     self.l2_distance_old = compute_color_l2(current_image=self.dirty_image,target_image=self.target_image)
     self.distance = None
     self.action_trajectory = []
     self.done = False
     # result = np.clip(self.current_image*255.0,a_min=0.0,a_max=255.0).astype(np.uint8)
     return self.current_image ,self.get_color_feature(self.current_image),self.get_gray_feature(self.current_image)