from dataloader import * import torch from torchvision import transforms from R2D2 import * from loss import * from torch.utils.data import DataLoader dataset = R2D2Dataset( root_dir='/media/jhyeup/5666b044-8f1b-47ad-83f3-d0acf3c6ec52/r2d2data/') # len(dataset) = 8406 image1, image2, meta = dataset.__getitem__(4) r2d2 = R2D2() r2d2.to(torch.device('cuda')) #input = torch.cat([image1, image2]) #input = input.to(torch.device('cuda')) """ image1 = image1.to(torch.device('cuda')) image2 = image2.to(torch.device('cuda')) meta['grid'] = meta['grid'].to(torch.device('cuda')) if 'mask' in meta : meta['mask'] = meta['mask'].to(torch.device('cuda')) d, rl, rp = r2d2.forward([image1, image2]) """ cosimloss = CosimLoss().to(torch.device('cuda')) for i in range(10): image1, image2, meta = dataset.__getitem__(i) image1 = image1.to(torch.device('cuda')) image2 = image2.to(torch.device('cuda'))
import sys import os try: caseid except NameError: print("input caseid id (3 digit)") caseid = 0 caseid = input() caseid = "d" + caseid.zfill(3) datadir = "../run/" + caseid + "/data/" pngdir = "../figs/" + caseid + "/ro_slice/" os.makedirs(pngdir, exist_ok=True) d = R2D2.R2D2_data(datadir) for key in d.p: exec('%s = %s%s%s' % (key, 'd.p["', key, '"]')) try: n0 except NameError: n0 = 0 if n0 > nd_tau: n0 = nd_tau print("Maximum time step= ",nd_tau," time ="\ ,dtout*float(nd)/3600./24.," [day]") plt.close('all')
import Environment import time import R2D2 import random num_episodes = 100000 env = Environment.Environment() agent = R2D2.R2D2(env) epsilon = 1 epsilon_decay = 0.99995 epsilon_min = 0.01 eps_count = 0 buffer_size = 10000 buffer = [] max_reward = 0 for e in range(num_episodes): st = env.reset() episode_reward = 0 t = 0 while True: at = agent.getAction(st, epsilon) st1, rt, done, debug = env.step(at) episode_reward += rt timestep = [st, at, rt, st1, done]
import R2D2 line1 = [] line2 = [] line3 = [] line4 = [] line5 = [] line6 = [] line7 = [] Driver = R2D2.Driver() camara = R2D2.Vision() try: stream = R2D2.Stream(str(R2D2.config('IP')), int(R2D2.config('Port')), streamer=1) except: stream = None LF = R2D2.LineFollower(collectData=True) AI = R2D2.AI() try: while True: frame = camara.getFrame('COLOR') stream.Send(frame) try: stream.Send(frame) except: pass _, _, sensorArray1, sensorArray2, sensorArray3, sensorArray4 = LF.getProcessedImage(frame) if not line1:
from flask import Flask, request from R2D2 import * r2 = R2D2() app = Flask(__name__) @app.route("/") def index(): return """<html> <head> <title>R2D2</title> </head> <body> <a href="/set/dome/on">Dome On</a> <a href="/set/dome/off">Dome Off</a> <form action="" method="get"> <button name="dome" value="on">Dome On</button> <button name="dome" value="off">Dome Off</button> </form> </body> </html>""" @app.route("/set/<setting>/<value>") def set(setting, value): if setting == "dome": if value == "on": r2.DomeLights.Enable() elif value == "off":
elif 'J' in keys: output[5] = 1 elif 'L' in keys: output[6] = 1 elif 'K' in keys: output[7] = 1 elif 'Y' in keys: output[8] = 1 elif 'G' in keys: output[9] = 1 else: output[10] = 1 return output collectData = bool(R2D2.config('CollectData')) stream = R2D2.Stream(str(R2D2.config('IP')), int(R2D2.config('Port')), streamer=0) LF = R2D2.LineFollower(collectData=collectData) if not collectData: AI = R2D2.AI() last_time = time.time() line1 = [] line2 = [] line3 = [] line4 = [] line5 = [] line6 = []
LucksLabUtils_config.config("Quest_R2D2") OSU.system_command("echo $PATH") OSU.system_command("echo $CLASSPATH") opts = OSU.getopts("", [ "in_dir=", "out_dir=", "adapter=", "p=", "e=", "endcut=", "constrained_c=", "scale_rho_max=", "draw_all=", "most_count_tie_break=", "scaling_func=", "weight_paired=", "cap_rhos=", "pol_fp=" ]) print opts # This specifically calls R2D2.R2D2() assuming the user has specified the arguments: # in_dir, out_dir, adapter, e, endcut, constrained_c, scale_rho_max, draw_all, most_count_tie_break, scaling_func, weight_paired, cap_rhos, pol_fp # Only in_dir, out_dir, and adapter are truly required to run R2D2.R2D2(). Default values for the other parameters are set within R2D2.py. cotrans = R2D2.R2D2( opts['--in_dir'], opts['--out_dir'], opts['--adapter'], p=int(opts['--p']), e=int(opts['--e']), endcut=int(opts['--endcut']), constrained_c=float(opts['--constrained_c']), scale_rho_max=float(opts['--scale_rho_max']), draw_all=bool(opts['--draw_all'] == "True"), most_count_tie_break=bool(opts['--most_count_tie_break'] == "True"), scaling_func=opts['--scaling_func'], weight_paired=float(opts['--weight_paired']), cap_rhos=bool(opts["--cap_rhos"] == "True"), pol_fp=int(opts['--pol_fp']))
import time import R2D2 Driver = R2D2.Driver() camara = R2D2.Vision() stream = R2D2.Stream(str(R2D2.config('IP')), int(R2D2.config('Port')), streamer=1) # Do You Want to Collect Data or Test the Camara ? collect_data = bool(R2D2.config('CollectData')) try: last_time = time.time() while True: frame = camara.getFrame('COLOR') stream.Send(frame) if collect_data: move = stream.Receive(5200) Driver.move2motor(move) else: print(round(1 / (time.time() - last_time), 2)) last_time = time.time() finally: stream.stop() Driver.clear()
import R2D2 AI = R2D2.AI(train=True)