def preprocess_state(s_, position_, env, resize=arg.resize): if (not arg.preprocess_state): s_ = np.array(s_) return s_ for i in range(len(s_)): s_[i] = pre_process_screen(s_[i]) prep_s = [] for i in range(arg.num_frames): img = s_[i] if (i == arg.num_frames - 1 and arg.resize): add_rects(img=img, point=position_, env=env) img = cv2.resize(img, arg.wind_conv_wh, interpolation=cv2.INTER_AREA) # img = cv2.resize(img, (arg.wind_w, arg.wind_h), interpolation=cv2.INTER_AREA) prep_s.append(img) # if (arg.resize): # for i in range(arg.num_frames): # img = s_[i] # if(i == arg.num_frames -1 ): # add_rects(img=img, point=position_, env=env) # img = cv2.resize(img, arg.wind_conv_wh, interpolation=cv2.INTER_AREA) # # img = cv2.resize(img, (arg.wind_w, arg.wind_h), interpolation=cv2.INTER_AREA) # prep_s.append(img) # # print(len(s_), env.num_frames) # else: # img = s_[-1] # add_rects(img=img, point=position_, env=env) # prep_s = s_ prep_s = np.array(prep_s) return prep_s # s_
def get_pre_state(self, screens=None): if (screens == None): self.get_state() screens_0 = [] for screen in screens: screen = pre_process_screen(screen) screens_0.append(screen) return screens_0
def step(self, action): s_ = self.get_state(action) position = self.get_position(s, template=env.my_underwear_bgr) s_ = pre_process_screen(s_) r, done, info = self.get_feedback(s_) # r, s_,info = 0,0,[position] r = 0 info = [self.position] self.s = s_ self.steps += 1 return s_, r, done, info
# print(sum(env.rewards), sum(env.rewards_d), env.rewards_p) # print('{5:2f}, {:5.2f}, {:5.3f}, {:5.3f},'.format( (ep_r, sum(env.rewards), sum(env.rewards_d), sum(env.rewards_p)) ) # print('{:5.2f}, {:5.3f}, {:5.3f},'.format( ep_r, sum(env.rewards_d), sum(env.rewards_p) )) # r, r_d, r_p = sum(env.rewards), sum(env.rewards_d), sum(env.rewards_p) # if (r_p != 0): # d_p = r_d / r_p # else: # d_p = -1 # plot if (arg.show_pre_image): # img = s_[-1] if (arg.show_orig_img): img = pre_process_screen(img, ret_type=arg.img_ret_type) add_rects(img=img, point=position_, env=env) # img = cv2.resize(img, (800, 600), interpolation=cv2.INTER_AREA) else: img = s_[-1] if (arg.show_resize_img): img = cv2.resize(img, (800, 600), interpolation=cv2.INTER_AREA) if (cv_img(img)): break_flag = 1 break if (model.memory_counter > MEMORY_CAPACITY and steps % arg.LEARN_TMP_STEP == 0):
if (len(s) != env.num_frames): print('error len!') ############################################################ action = np.random.choice(env.action_space) # action = model(s) s_ = env.get_state(action) r, done, info = env.get_feedback(s_) ################### ------------------- if (not done): # plot cv_img position_ = info[0] img = s_[-1] # point = position_ if (arg.control_preprocess_img): img = pre_process_screen(img) # if (cv_img(img)): break_flag = 1; break img_add_rect(img=img, point=position_, ptype=arg.ptype, pcolor=arg.pcolor, ww=10, hh=20, cut=1) img_add_rect(img=img, point=env.end, ptype=arg.ptype_dest, pcolor=arg.pcolor_dest, ww=20, hh=20) # if (cv_img(img)): break_flag = 1; break