def main(args): # parsing arguments mode = args[1] # identify, mpc folder_frame_in = args[2] folder_frame_out = args[3] folder_results = args[4] setpoint_quality = float(args[5]) setpoint_compression = float(args[6]) # getting frames and opening result file path, dirs, files = os.walk(folder_frame_in).next() frame_count = len(files) final_frame = frame_count + 1 log = open(folder_results + '/results.csv', 'w') if mode == "mpc": controller = mpccontroller.initialize_mpc() elif mode == "random": controller = randomcontroller.RandomController() elif mode == "bangbang": controller = bangbangcontroller.BangbangController() # initial values for actuators ctl = np.matrix([[100], [0], [0]]) for i in range(1, final_frame): # main loop ut.progress(i, final_frame) # display progress bar quality = np.round(ctl.item(0)) sharpen = np.round(ctl.item(1)) noise = np.round(ctl.item(2)) # encoding the current frame (current_quality, current_size) = \ encode(i, folder_frame_in, folder_frame_out, quality, sharpen, noise) log_line = '{i}, {quality}, {sharpen}, {noise}, {ssim}, {size}'.format( i = i, quality = quality, sharpen = sharpen, noise = noise, ssim = current_quality, size = current_size) print >>log, log_line setpoints = np.matrix([[setpoint_quality], [setpoint_compression]]) current_outputs = np.matrix([[current_quality], [current_size]]) # computing actuator values for the next frame if mode == "mpc": try: ctl = controller.compute_u(current_outputs, setpoints) except Exception: pass elif mode == "random": ctl = controller.compute_u() elif mode == "bangbang": ctl = controller.compute_u(current_outputs, setpoints) print " done"
def main(args): ssim = [] size = [] # parsing arguments mode = args[1] # identify, mpc folder_frame_in = args[2] # frames/ONE/orig folder_frame_out = args[3] # frames/ONE/proc/bangbang-Q0.2-F500000 folder_results = args[4] # results/ONE/bangbang-Q0.2-F500000 setpoint_quality = float(args[5]) # similarity index setpoint_compression = float(args[6]) # frame size in kb # getting frames and opening result file path, dirs, files = os.walk(folder_frame_in).next() frame_count = len(files) final_frame = frame_count + 1 # +1 for forloop log = open(folder_results + '/results.csv', 'w') if mode == "mpc": # check if its mpc random or bangbang controller = mpccontroller.initialize_mpc() elif mode == "random": # if its random now controller. will only point to random # controller class controller = randomcontroller.RandomController() elif mode == "closed_loop": controller = closedloopcontroller.ClosedLoopController() print "hello1" elif mode == "pid": controller = pidcontroller.PidController() # initial values for actuators ctl = np.matrix([[30], [0], [0]]) sizes = [] for i in range(1, final_frame): sizes.append(i) # main loop ut.progress(i, final_frame) # display progress bar quality = np.round(ctl.item(0)) # 100 sharpen = np.round(ctl.item(1)) # 0 noise = np.round(ctl.item(2)) # 0 # encoding the current frame # ssim and size is returned via encode (current_quality, current_size) = \ encode(i, folder_frame_in, folder_frame_out, quality, sharpen, noise) log_line = '{i}, {quality}, {sharpen}, {noise}, {ssim}, {size}'.format( i=i, quality=quality, sharpen=sharpen, noise=noise, ssim=current_quality, size=current_size) print >> log, log_line # the values of quality and size that we give in the terminal setpoints = np.matrix([[setpoint_quality], [setpoint_compression]]) #print setpoints # contains the current quality and size of the frame current_outputs = np.matrix([[current_quality], [current_size]]) # computing actuator values for the next frame ssim.append(current_outputs.item(0)) size.append(current_outputs.item(1)) if mode == "mpc": try: ctl = controller.compute_u(current_outputs, setpoints) print current_outputs.item(1) print current_outputs.item(0) print "quality" print ctl.item(0) print "sharpness" print ctl.item(1) print "noise" print ctl.item(2) except Exception: pass elif mode == "random": ctl = controller.compute_u() elif mode == "closed_loop": ctl = controller.compute_u(current_outputs, setpoints) elif mode == "pid": ctl = controller.compute_u(current_outputs, setpoints) print " done"
def main(args): # parsing arguments mode = args[1] # identify, mpc folder_frame_in = args[2] folder_frame_out = args[3] folder_results = args[4] setpoint_quality = float(args[5]) setpoint_compression = float(args[6]) # getting frames and opening result file path, dirs, files = os.walk(folder_frame_in).next() frame_count = len(files) final_frame = frame_count + 1 log = open(folder_results + '/results.csv', 'w') if mode == "mpc": controller = mpccontroller.initialize_mpc() elif mode == "random": controller = randomcontroller.RandomController() elif mode == "bangbang": controller = bangbangcontroller.BangbangController() elif mode == "integral": controller = integralcontroller.IntegralController() elif mode == "greedy": controller = greedycontroller.GreedyController() # initial values for actuators ctl = np.matrix([[100], [0], [0]]) # initialize performance parameter integrated_ssim_error = 0.0 integrated_size_error = 0.0 for i in range(1, final_frame): # main loop ut.progress(i, final_frame) # display progress bar quality = np.round(ctl.item(0)) sharpen = np.round(ctl.item(1)) noise = np.round(ctl.item(2)) # encoding the current frame (current_quality, current_size) = \ encode(i, folder_frame_in, folder_frame_out, quality, sharpen, noise) log_line = '{i}, {quality}, {sharpen}, {noise}, {ssim}, {size}'.format( i=i, quality=quality, sharpen=sharpen, noise=noise, ssim=current_quality, size=current_size) print >> log, log_line setpoints = np.matrix([[setpoint_quality], [setpoint_compression]]) current_outputs = np.matrix([[current_quality], [current_size]]) # compute integrated error with relu error = np.subtract(setpoints, current_outputs) ssim_error = error.item(0) size_error = error.item(1) if (ssim_error > 0.0): integrated_ssim_error = integrated_ssim_error + ssim_error if (size_error < 0.0): integrated_size_error = integrated_size_error - size_error # computing actuator values for the next frame if mode == "mpc": try: ctl = controller.compute_u(current_outputs, setpoints) except Exception: pass elif mode == "random": ctl = controller.compute_u() elif mode == "bangbang": ctl = controller.compute_u(current_outputs, setpoints) elif mode == "integral": ctl = controller.compute_u(current_outputs, setpoints) elif mode == "greedy": action = np.matrix([[quality], [sharpen], [noise]]) ctl = controller.compute_u(current_outputs, setpoints, action) # end of loop over the frames # divide by number of frames to obtain weighted error average_ssim_error = integrated_ssim_error / final_frame average_size_error = integrated_size_error / final_frame # print to file performance parameter tmp = folder_frame_in.split('/') video_name = tmp[2] folder_name = tmp[1] log_performance_parameter = open( 'results/summary/' + mode + '/performance_log_' + folder_name + '.csv', 'a') log_line_performance = '{video}, {controller}, {target_ssim}, {target_size}, {average_ssim_error}, {average_size_error}'.format( video=video_name, controller=mode, target_ssim=setpoint_quality, target_size=setpoint_compression, average_ssim_error=average_ssim_error, average_size_error=average_size_error) print >> log_performance_parameter, log_line_performance print " done"
size CHAR(50));''') print ("Table result created successfully") c.execute('''CREATE TABLE netinfo (net TEXT NOT NULL, icmp_seq char(50) NOT NULL, ttl CHAR(50), min_avg_max_mdev CHAR(50), timest CHAR(50));''') print ("Table netinfo created successfully") #sys.stdout = log if mode == "mpc": controller = mpccontroller.initialize_mpc() elif mode == "random": controller = randomcontroller.RandomController() elif mode == "bangbang": controller = bangbangcontroller.BangbangController() # elif mode == "pid": # controller = pidcontroller.PidController() # elif mode == "closed_loop": # controller = closedloopcontroller.ClosedLoopController() # initial values for actuators ctl = np.matrix([[100], [0], [0]]) for i in range(1, final_frame): # main loop ut.progress(i, final_frame) # display progress bar quality = np.round(ctl.item(0))