def search(target, worklist, callbacks): global ninput callback_start_scoring = callbacks[6] callback_scored = callbacks[7] callback_start_check = callbacks[8] callback_checked = callbacks[9] while worklist: input = worklist.pop() #print '[+] input %s' % input.filename child_inputs = expand_execution(input, callbacks) if not callback_start_check: print '[+] checking each new input' else: callback_start_check(len(child_inputs)) for input in child_inputs: if not callback_checked: os.write(sys.stdout.fileno(), ' %s' % input.filename.split('/')[-1]) fault = check(PARAM['PROGNAME'], PARAM['PROGARG'], input.filename, PARAM['FAULT_CHECKER'], PARAM['TAINT_STDIN']) if not callback_checked: os.write(sys.stdout.fileno(), '\b' * (len(input.filename.split('/')[-1]) + 4)) if fault: print '[+] ' + ('@' * 75) print ' Fault detected on file %s' % input.filename.split('/')[-1] print ' ' + ('@' * 75) else: callback_checked(input.number, fault) if fault: filecopy = os.path.join(PARAM['CRASH_FOLDER'], os.path.basename(input.filename)) shutil.copy(input.filename, filecopy) if not callback_start_scoring: print '[+] scoring each new input' else: callback_start_scoring(len(child_inputs)) for input in child_inputs: if not callback_scored: os.write(sys.stdout.fileno(), ' %s' % input.filename.split('/')[-1]) input.note = score(PARAM['PROGNAME'], PARAM['PROGARG'], input.filename, PARAM['TAINT_STDIN']) #input.note = random_score() if not callback_scored: os.write(sys.stdout.fileno(), '\b' * (len(input.filename.split('/')[-1]) + 4)) else: callback_scored(input) worklist += child_inputs worklist.sort(key=lambda x: x.note) # this is couner-intuitive, but a lot of blocks are executed on # completely wrong images if PARAM['PROGNAME'] == '/usr/bin/convert': worklist.reverse() session.save(target, PARAM, ninput, worklist)
def train(self, learning_rate, step_num, init_step=None, restoring_file=None): print('\n%s: training...' % datetime.now()) sys.stdout.flush() session = Session(self._graph, self.models_dir) init_step = session.init(self._network, init_step, restoring_file) session.start() last_step = init_step+step_num print('%s: training till: %d steps' %(datetime.now(), last_step)) print_loss = 0 train_loss = None save_loss = 0 save_step = 0 total_loss = 0 feed_dict={self._lr_placeholder: learning_rate} for step in range(init_step+1, last_step+1): start_time = time.time() _, total_loss_batch, loss_batch = session.run( [self._train, self._total_loss, self._cross_entropy_losses], feed_dict=feed_dict ) duration = time.time() - start_time assert not np.isnan(total_loss_batch), 'Model diverged with loss = NaN' cross_entropy_loss_value = np.mean(loss_batch) print_loss += cross_entropy_loss_value save_loss += cross_entropy_loss_value total_loss += total_loss_batch save_step += 1 if ((step - init_step) % Trainer.PRINT_FREQUENCY == 0): examples_per_sec = Trainer.BATCH_SIZE / duration format_str = ('%s: step %d, loss = %.2f, lr = %f, ' '(%.1f examples/sec; %.3f sec/batch)') print_loss /= Trainer.PRINT_FREQUENCY print(format_str % (datetime.now(), step, print_loss, learning_rate, examples_per_sec, float(duration))) print_loss = 0 # Save the model checkpoint and summaries periodically. if (step == last_step or (Trainer.SAVE_FREQUENCY is not None and (step - init_step) % Trainer.SAVE_FREQUENCY == 0)): session.save(step) total_loss /= save_step train_loss = save_loss / save_step print('%s: train_loss = %.3f' % (datetime.now(), train_loss)) if (self.writer): summary_str = session.run(self._all_summaries, feed_dict=feed_dict) self.writer.write_summaries(summary_str, step) self.writer.write_scalars({'losses/training/cross_entropy_loss': train_loss, 'losses/training/total_loss': total_loss}, step) total_loss = 0 save_loss = 0 save_step = 0 session.stop() return step, train_loss
def yes_fun(): path, _ = QFileDialog.getSaveFileName(self, filter='(*.yaml)') try: session.save(path, self.d_fp, self.s_fp, self.min_dur, str(self.f_ind)) self.exit() except FileNotFoundError: self.annotator.status('unable to find: \'{}\''.format(path)) self.open()
def _writeImage(request): number = str(random.randrange(1,99999,1)) session = request.getSession() session["nospam"] = number session.save() image = _generateImage(number) response = request.getResponse() response.addHeader('Content-Type', 'image/png') image.save(response, "PNG")
def train(self, learning_rate, step_num, init_step=None, restoring_file=None): print('%s: training...' % datetime.now()) sys.stdout.flush() session = Session(self._graph, self.models_dir) init_step = session.init(self._network, init_step, restoring_file) session.start() last_step = init_step+step_num print('%s: training till: %d steps' %(datetime.now(), last_step)) print_loss = 0 train_loss = None save_loss = 0 save_step = 0 feed_dict={self._lr_placeholder: learning_rate} for step in range(init_step+1, last_step+1): start_time = time.time() _, loss_batch = session.run([self._train, self._loss], feed_dict=feed_dict) duration = time.time() - start_time assert not np.isnan(loss_batch), 'Model diverged with loss = NaN' print_loss += loss_batch save_loss += loss_batch save_step += 1 if ((step - init_step) % Trainer.PRINT_FREQUENCY == 0): examples_per_sec = Trainer.BATCH_SIZE / duration format_str = ('%s: step %d, loss = %.2f, lr = %f, ' '(%.1f examples/sec; %.3f sec/batch)') print_loss /= Trainer.PRINT_FREQUENCY print(format_str % (datetime.now(), step, print_loss, learning_rate, examples_per_sec, float(duration))) print_loss = 0 # Save the model checkpoint and summaries periodically. if (step == last_step or (Trainer.SAVE_FREQUENCY is not None and (step - init_step) % Trainer.SAVE_FREQUENCY == 0)): session.save(step) train_loss = save_loss / save_step print('%s: train_loss = %.3f' % (datetime.now(), train_loss)) save_loss = 0 save_step = 0 if (self.writer): summary_str = session.run(self._all_summaries, feed_dict=feed_dict) self.writer.write_summaries(summary_str, step) self.writer.write_scalars({'losses/training/total_loss': train_loss}, step) session.stop() return step, train_loss
def search(target, worklist, callbacks): global ninput global paths global elapsed global querytime global start global pathssub global totalcon global cva_constraints global cva_paths callback_start_scoring = callbacks[6] callback_scored = callbacks[7] callback_start_check = callbacks[8] callback_checked = callbacks[9] accumlist = list(worklist) current = ninput #session.save(target, PARAM, ninput, worklist) #start = time.time() while worklist: #start = time.time() input = worklist.pop() #print '[+] input %s' % input.filename child_inputs = expand_execution(input, callbacks) if USE_ACCUM: continue if PARAM['PATH_BOUND'] > 0 and paths >= PARAM['PATH_BOUND']: if not USE_ACCUM: accumlist += child_inputs break; if not callback_start_check: print '[+] checking each new input' else: callback_start_check(len(child_inputs)) for input in child_inputs: if not callback_checked: os.write(sys.stdout.fileno(), ' %s' % input.filename.split('/')[-1]) fault = check(PARAM['PROGNAME'], PARAM['PROGARG'], input.filename, PARAM['FAULT_CHECKER'], PARAM['TAINT_STDIN']) if not callback_checked: os.write(sys.stdout.fileno(), '\b' * (len(input.filename.split('/')[-1]) + 4)) if fault: print '[+] ' + ('@' * 75) print ' Fault detected on file %s' % input.filename.split('/')[-1] print ' ' + ('@' * 75) else: callback_checked(input.number, fault) if fault: filecopy = os.path.join(PARAM['CRASH_FOLDER'], os.path.basename(input.filename)) shutil.copy(input.filename, filecopy) #elapsed = elapsed + (time.time() - start) if not callback_start_scoring: print '[+] scoring each new input' else: callback_start_scoring(len(child_inputs)) for input in child_inputs: if not callback_scored: os.write(sys.stdout.fileno(), ' %s' % input.filename.split('/')[-1]) input.note = score(PARAM['PROGNAME'], PARAM['PROGARG'], input.filename, PARAM['TAINT_STDIN']) #input.note = random_score() if not callback_scored: os.write(sys.stdout.fileno(), '\b' * (len(input.filename.split('/')[-1]) + 4)) else: callback_scored(input) worklist += child_inputs accumlist += child_inputs worklist.sort(key=lambda x: x.note) #worklist.sort(key=lambda x: x.note, reverse = True) #worklist.reverse() # this is counter-intuitive, but a lot of blocks are executed on # completely wrong images if PARAM['PROGNAME'] == '/usr/bin/convert': worklist.reverse() #session.save(target, PARAM, ninput, worklist) elapsed = (time.time() - start) session.save(target, PARAM, ninput, accumlist) print 'Paths Explored: %s Feasible Paths: %s Total Constraints: %s Actual Constraints: %s Time Taken: %s Valgrind Time: %s'\ % (paths,ninput - current,totalcon,pathssub,round(elapsed,2),round(querytime,2))
def search(target, worklist, callbacks): global ninput global paths global elapsed global querytime global start global pathssub global totalcon global cva_constraints global cva_paths global graphplot global x global y global pcstrings callback_start_scoring = callbacks[6] callback_scored = callbacks[7] callback_start_check = callbacks[8] callback_checked = callbacks[9] accumlist = list(worklist) current = ninput #session.save(target, PARAM, ninput, worklist) #start = time.time() while worklist: #start = time.time() input = worklist.pop() #print '[+] input %s' % input.filename child_inputs = expand_execution(input, callbacks) if USE_ACCUM: continue if PARAM['PATH_BOUND'] > 0 and paths >= PARAM['PATH_BOUND']: if not USE_ACCUM: accumlist += child_inputs break; if not callback_start_check: print '[+] checking each new input' else: callback_start_check(len(child_inputs)) for input in child_inputs: if not callback_checked: os.write(sys.stdout.fileno(), ' %s' % input.filename.split('/')[-1]) fault = check(PARAM['PROGNAME'], PARAM['PROGARG'], input.filename, PARAM['FAULT_CHECKER'], PARAM['TAINT_STDIN']) if not callback_checked: os.write(sys.stdout.fileno(), '\b' * (len(input.filename.split('/')[-1]) + 4)) if fault: print '[+] ' + ('@' * 75) print ' Fault detected on file %s' % input.filename.split('/')[-1] print ' ' + ('@' * 75) else: callback_checked(input.number, fault) if fault: filecopy = os.path.join(PARAM['CRASH_FOLDER'], os.path.basename(input.filename)) shutil.copy(input.filename, filecopy) #elapsed = elapsed + (time.time() - start) if not callback_start_scoring: print '[+] scoring each new input' else: callback_start_scoring(len(child_inputs)) for input in child_inputs: if not callback_scored: os.write(sys.stdout.fileno(), ' %s' % input.filename.split('/')[-1]) input.note = score(PARAM['PROGNAME'], PARAM['PROGARG'], input.filename, PARAM['TAINT_STDIN']) #input.note = random_score() if not callback_scored: os.write(sys.stdout.fileno(), '\b' * (len(input.filename.split('/')[-1]) + 4)) else: callback_scored(input) worklist += child_inputs accumlist += child_inputs worklist.sort(key=lambda x: x.note) #worklist.sort(key=lambda x: x.note, reverse = True) #worklist.reverse() # this is counter-intuitive, but a lot of blocks are executed on # completely wrong images if PARAM['PROGNAME'] == '/usr/bin/convert': worklist.reverse() #session.save(target, PARAM, ninput, worklist) elapsed = (time.time() - start) session.save(target, PARAM, ninput, accumlist) print 'Paths Explored: %s Feasible Paths: %s Total Constraints: %s Actual Constraints: %s Time Taken: %s Valgrind Time: %s'\ % (paths,ninput - current,totalcon,pathssub,round(elapsed,2),round(querytime,2)) sx = [] radii = [] sy = [] i = 0; j = 0; for s1 in pcstrings : j = 0; for s2 in pcstrings : sx.append(i) sy.append(j) #print 's1 : %s' %s1 #print 's2 : %s' %s2 #sim = difflib.SequenceMatcher(a=s1.lower(),b=s2.lower()).ratio() sim = Levenshtein.seqratio(s1,s2) radii.append(0.05+(sim/5)) #print 'sx : %d' %i #print 'sy : %d' %j #print 'sim : %s' %round(sim,2) j += 1 i += 1 output_server("Similarity Visualization") TOOLS="resize,crosshair,pan,wheel_zoom,box_zoom,reset,tap,previewsave,box_select,poly_select,lasso_select" p = figure(tools=TOOLS) p.scatter(sx,sy,radius=radii,color='red',fill_alpha=0.6,name='pathsscatter') p.title = "Path Similarity : "+target p.xaxis.axis_label = 'Number' p.yaxis.axis_label = 'Number' show(p)
) print( "Terima kasih telah menggunakan aplikasi Kantong Ajaib >_<" ) status_sesi = False status_apps = False else: aksi = str( input( "Data perubahan terakhir belum disave, save sekarang (Y/N)? " )) if aksi == 'y' or aksi == "Y": session.save(array_of_user, array_of_gadget, array_of_consumable, array_of_gadget_borrow_history, array_of_gadget_return_history, array_of_consumable_history) # akan tetap melakukan save di directory awal (walaupun pilihan folder save di directory lain) saved_data_gadget = preparation.loadAndRefreshCSV( str(rootbaru + "\\" + folderbaru + "\\" + "gadget.csv")) saved_data_consumable = preparation.loadAndRefreshCSV( str(rootbaru + "\\" + folderbaru + "\\" + "consumable.csv")) saved_data_gadget_borrow_history = preparation.loadAndRefreshCSV( str(rootbaru + "\\" + folderbaru + "\\" + "gadget_borrow_history.csv")) saved_data_gadget_return_history = preparation.loadAndRefreshCSV( str(rootbaru + "\\" + folderbaru + "\\" +
def save_session(self, app, session, response): session.save()
def search(target, worklist, callbacks): global ninput global paths global elapsed global querytime global start global pathssub global totalcon global cva_constraints global cva_paths callback_start_scoring = callbacks[6] callback_scored = callbacks[7] callback_start_check = callbacks[8] callback_checked = callbacks[9] accumlist = list(worklist) current = ninput #session.save(target, PARAM, ninput, worklist) #start = time.time() while worklist: #start = time.time() input = worklist.pop() #print '[+] input %s' % input.filename child_inputs = expand_execution(input, callbacks) if USE_ACCUM: continue if PARAM['PATH_BOUND'] > 0 and paths >= PARAM['PATH_BOUND']: if not USE_ACCUM: accumlist += child_inputs break if not callback_start_check: print '[+] checking each new input' else: callback_start_check(len(child_inputs)) for input in child_inputs: if not callback_checked: os.write(sys.stdout.fileno(), ' %s' % input.filename.split('/')[-1]) fault = check(PARAM['PROGNAME'], PARAM['PROGARG'], input.filename, PARAM['FAULT_CHECKER'], PARAM['TAINT_STDIN']) if not callback_checked: os.write(sys.stdout.fileno(), '\b' * (len(input.filename.split('/')[-1]) + 4)) if fault: print '[+] ' + ('@' * 75) print ' Fault detected on file %s' % input.filename.split( '/')[-1] print ' ' + ('@' * 75) else: callback_checked(input.number, fault) if fault: filecopy = os.path.join(PARAM['CRASH_FOLDER'], os.path.basename(input.filename)) shutil.copy(input.filename, filecopy) #elapsed = elapsed + (time.time() - start) if not callback_start_scoring: print '[+] scoring each new input' else: callback_start_scoring(len(child_inputs)) for input in child_inputs: if not callback_scored: os.write(sys.stdout.fileno(), ' %s' % input.filename.split('/')[-1]) input.note = score(PARAM['PROGNAME'], PARAM['PROGARG'], input.filename, PARAM['TAINT_STDIN']) #input.note = random_score() if not callback_scored: os.write(sys.stdout.fileno(), '\b' * (len(input.filename.split('/')[-1]) + 4)) else: callback_scored(input) worklist += child_inputs accumlist += child_inputs worklist.sort(key=lambda x: x.note) #worklist.sort(key=lambda x: x.note, reverse = True) #worklist.reverse() # this is counter-intuitive, but a lot of blocks are executed on # completely wrong images if PARAM['PROGNAME'] == '/usr/bin/convert': worklist.reverse() #session.save(target, PARAM, ninput, worklist) elapsed = (time.time() - start) session.save(target, PARAM, ninput, accumlist) print 'Paths Explored: %s Feasible Paths: %s Total Constraints: %s Actual Constraints: %s Time Taken: %s Valgrind Time: %s'\ % (paths,ninput - current,totalcon,pathssub,round(elapsed,2),round(querytime,2))
def search(target, worklist, callbacks): global ninput callback_start_scoring = callbacks[6] callback_scored = callbacks[7] callback_start_check = callbacks[8] callback_checked = callbacks[9] while worklist: input = worklist.pop() #print '[+] input %s' % input.filename child_inputs = expand_execution(input, callbacks) if not callback_start_check: print '[+] checking each new input' else: callback_start_check(len(child_inputs)) for input in child_inputs: if not callback_checked: os.write(sys.stdout.fileno(), ' %s' % input.filename.split('/')[-1]) fault = check(PARAM['PROGNAME'], PARAM['PROGARG'], input.filename, PARAM['FAULT_CHECKER'], PARAM['TAINT_STDIN']) if not callback_checked: os.write(sys.stdout.fileno(), '\b' * (len(input.filename.split('/')[-1]) + 4)) if fault: print '[+] ' + ('@' * 75) print ' Fault detected on file %s' % input.filename.split( '/')[-1] print ' ' + ('@' * 75) else: callback_checked(input.number, fault) if fault: filecopy = os.path.join(PARAM['CRASH_FOLDER'], os.path.basename(input.filename)) shutil.copy(input.filename, filecopy) if not callback_start_scoring: print '[+] scoring each new input' else: callback_start_scoring(len(child_inputs)) for input in child_inputs: if not callback_scored: os.write(sys.stdout.fileno(), ' %s' % input.filename.split('/')[-1]) input.note = score(PARAM['PROGNAME'], PARAM['PROGARG'], input.filename, PARAM['TAINT_STDIN']) #input.note = random_score() if not callback_scored: os.write(sys.stdout.fileno(), '\b' * (len(input.filename.split('/')[-1]) + 4)) else: callback_scored(input) worklist += child_inputs worklist.sort(key=lambda x: x.note) # this is couner-intuitive, but a lot of blocks are executed on # completely wrong images if PARAM['PROGNAME'] == '/usr/bin/convert': worklist.reverse() session.save(target, PARAM, ninput, worklist)
def shutdown(): global shutting_down print('*Shutting down...') shutting_down = True session.save()
def search(target, worklist, callbacks): global ninput global paths global elapsed global querytime global start global pathssub global totalcon global cva_constraints global cva_paths global graphplot global x global y global pcstrings callback_start_scoring = callbacks[6] callback_scored = callbacks[7] callback_start_check = callbacks[8] callback_checked = callbacks[9] accumlist = list(worklist) current = ninput #session.save(target, PARAM, ninput, worklist) #start = time.time() while worklist: #start = time.time() input = worklist.pop() #print '[+] input %s' % input.filename child_inputs = expand_execution(input, callbacks) if USE_ACCUM: continue if PARAM['PATH_BOUND'] > 0 and paths >= PARAM['PATH_BOUND']: if not USE_ACCUM: accumlist += child_inputs break if not callback_start_check: print '[+] checking each new input' else: callback_start_check(len(child_inputs)) for input in child_inputs: if not callback_checked: os.write(sys.stdout.fileno(), ' %s' % input.filename.split('/')[-1]) fault = check(PARAM['PROGNAME'], PARAM['PROGARG'], input.filename, PARAM['FAULT_CHECKER'], PARAM['TAINT_STDIN']) if not callback_checked: os.write(sys.stdout.fileno(), '\b' * (len(input.filename.split('/')[-1]) + 4)) if fault: print '[+] ' + ('@' * 75) print ' Fault detected on file %s' % input.filename.split( '/')[-1] print ' ' + ('@' * 75) else: callback_checked(input.number, fault) if fault: filecopy = os.path.join(PARAM['CRASH_FOLDER'], os.path.basename(input.filename)) shutil.copy(input.filename, filecopy) #elapsed = elapsed + (time.time() - start) if not callback_start_scoring: print '[+] scoring each new input' else: callback_start_scoring(len(child_inputs)) for input in child_inputs: if not callback_scored: os.write(sys.stdout.fileno(), ' %s' % input.filename.split('/')[-1]) input.note = score(PARAM['PROGNAME'], PARAM['PROGARG'], input.filename, PARAM['TAINT_STDIN']) #input.note = random_score() if not callback_scored: os.write(sys.stdout.fileno(), '\b' * (len(input.filename.split('/')[-1]) + 4)) else: callback_scored(input) worklist += child_inputs accumlist += child_inputs worklist.sort(key=lambda x: x.note) #worklist.sort(key=lambda x: x.note, reverse = True) #worklist.reverse() # this is counter-intuitive, but a lot of blocks are executed on # completely wrong images if PARAM['PROGNAME'] == '/usr/bin/convert': worklist.reverse() #session.save(target, PARAM, ninput, worklist) elapsed = (time.time() - start) session.save(target, PARAM, ninput, accumlist) print 'Paths Explored: %s Feasible Paths: %s Total Constraints: %s Actual Constraints: %s Time Taken: %s Valgrind Time: %s'\ % (paths,ninput - current,totalcon,pathssub,round(elapsed,2),round(querytime,2)) sx = [] radii = [] sy = [] i = 0 j = 0 for s1 in pcstrings: j = 0 for s2 in pcstrings: sx.append(i) sy.append(j) #print 's1 : %s' %s1 #print 's2 : %s' %s2 #sim = difflib.SequenceMatcher(a=s1.lower(),b=s2.lower()).ratio() sim = Levenshtein.seqratio(s1, s2) radii.append(0.05 + (sim / 5)) #print 'sx : %d' %i #print 'sy : %d' %j #print 'sim : %s' %round(sim,2) j += 1 i += 1 output_server("Similarity Visualization") TOOLS = "resize,crosshair,pan,wheel_zoom,box_zoom,reset,tap,previewsave,box_select,poly_select,lasso_select" p = figure(tools=TOOLS) p.scatter(sx, sy, radius=radii, color='red', fill_alpha=0.6, name='pathsscatter') p.title = "Path Similarity : " + target p.xaxis.axis_label = 'Number' p.yaxis.axis_label = 'Number' show(p)