observation_big, reward, done, info = env.step(action) # we can resize the image here observation = cv2.resize(observation_big, (80, 60)) # NOTICE: OpenCV changes the order of the channels !!! observation = cv2.cvtColor(observation, cv2.COLOR_BGR2RGB) #observation = cv2.cvtColor(observation, cv2.COLOR_BGR2GRAY) flip_action = (action[0], -action[1]) flip_observation = cv2.flip(observation, 1) except: break # we may use this to debug our expert. if DEBUG: cv2.imshow('debug', cv2.resize(observation, (0, 0), fx=3, fy=3)) cv2.waitKey(1) logger.log(observation, action, reward, done, info) logger.log(flip_observation, flip_action, reward, done, info) # [optional] env.render() to watch the expert interaction with the environment # we log here logger.on_episode_done() # speed up logging by flushing the file env.reset() # we flush everything and close the file, it should be ~ 120mb # NOTICE: we make the log file read-only, this prevent us from erasing all collected data by mistake # believe me, this is an important issue... can you imagine loosing 2 GB of data? No? We do... logger.close() env.close()
closest_point, _ = env.closest_curve_point(env.cur_pos, env.cur_angle) if closest_point is None: done = True break # Cut the horizon: obs.shape = (480,640,3) --> (300,640,3) observation = observation[150:450, :] # we can resize the image here observation = cv2.resize(observation, (120, 60)) # NOTICE: OpenCV changes the order of the channels !!! observation = cv2.cvtColor(observation, cv2.COLOR_BGR2RGB) # we may use this to debug our expert. if DEBUG: cv2.imshow('debug', observation) cv2.waitKey(1) logger.log(observation, action, reward, done, info) logger.on_episode_done() # speed up logging by flushing the file env.reset() logger.close() env.close() end_time = time.time() print( f"Process finished. It took {(end_time - start_time) / (60*60):.2f} hours!" )