img_np = np.asarray(img).reshape( HEIGHT, WIDTH, 3)[:, :, ::-1] #.astype('uint8') # HWC, RGB # import pdb; pdb.set_trace() #plt.imshow(img_np) #plt.show() img_np = (img_np / 255).astype('float32') x = trn_tfms( img_np )[np.newaxis, ...] # shape (210, 280, 3) -> (3, 210, 210) -> (1, 3, 210, 210) x = Variable(T(x), requires_grad=False, volatile=True) output = learner.model(x, None) # shape (1, 14) pred_indicators = transform_range_output(to_np(output[0]), desired_ranges, output_ranges) print("network raw output", output) print("pred_indicators", pred_indicators) indicators_formatted = format_indicators(pred_indicators) print("indicators_formatted", indicators_formatted) ground_truth = drive.read_indicators() print("ground_truth", ground_truth) drive.controller(indicators_formatted) drive.update_visualizations(indicators_formatted, ground_truth) drive.write(False) # Shared data read, and TORCS may continue drive.wait_key(1)
# drive.controller(ground_truth) # drive.write(False) # Shared data read, and TORCS may continue # Test 8: visualization @contextmanager def context(*args, **kwds): drive.setup_shared_memory() drive.setup_opencv() try: yield None finally: drive.close_shared_memory() drive.close_opencv() with context() as _: drive.pause(False) # TORCS may share images and ground truth print("Controlling: ", drive.is_controlling()) drive.set_control(True) print("Controlling: ", drive.is_controlling()) input("Press key to start...") while True: if drive.is_written(): ground_truth = drive.read_indicators() print(ground_truth) drive.controller(ground_truth) drive.update_visualizations(ground_truth, ground_truth) drive.write(False) # Shared data read, and TORCS may continue drive.wait_key(1)