def main(): while True: option = "" print("\n[0] Login" + "\n[1] Register" + "\n[2] Demo" + "\n[3] Exit") while option not in ["0", "1", "2", "3"]: option = input("\nSelect an option: ") if option == "0": login.login_as_user(demo=False, d_uname="", d_password="", d_features=[]) if option == "1": register.register_new_user(demo=False, d_uname="", d_password="", d_features=[]) if option == "2": demo.run_demo() if option == "3": print("Good Bye!") exit()
def main(): # DATA PREPARATION dataset = pd.read_csv('dataset.csv', encoding="ISO-8859-1") X_train, X_val, X_test, y_train, y_val, y_test, vect = prepare_dataset( dataset) # MODELS TRAINING print("\n--------------------------------------------------------") print("------------------- MODELS TRAINING -------------------") print("--------------------------------------------------------\n") # Random Forest modelRF = train_RF(X_train, y_train) eval_model(modelRF, X_val, y_val) # SVM modelSVC = train_SVC(X_train, y_train) eval_model(modelSVC, X_val, y_val) #NN modelNN = train_NN(X_train, y_train) eval_model(modelNN, X_val, y_val) # MODELS TESTING print("\n--------------------------------------------------------") print("-------------- MODELS TESTING (accuracy) --------------") print("--------------------------------------------------------\n") print("RANDOM FOREST: ", test_model(modelRF, X_test, y_test)) print("SVC: ", test_model(modelSVC, X_test, y_test)) print("NEURAL NETWORK: ", test_model(modelNN, X_test, y_test)) # RUN THE DEMO run_demo(vect, modelNN)
def infer_video( cfg, ckpt, video_path: str, score_threshold: float, dataset_type, output_path, video_images): assert pathlib.Path(video_path).is_file(),\ f"Did not find video: {video_path}" with tempfile.TemporaryDirectory() as cache_dir: if video_images: cache_dir = video_images input_image_dir = pathlib.Path(cache_dir, "input_images") input_image_dir.mkdir(exist_ok=True) with mp.VideoFileClip(video_path) as video: original_fps = video.fps dump_frames(video, input_image_dir) output_image_dir = pathlib.Path(cache_dir, "video_images") output_image_dir.mkdir(exist_ok=True) run_demo( cfg, ckpt, score_threshold, pathlib.Path(input_image_dir), output_image_dir, dataset_type) impaths = list(output_image_dir.glob("*.png")) impaths.sort(key=lambda impath: int(impath.stem.strip(".png"))) impaths = [str(impath) for impath in impaths] with mp.ImageSequenceClip(impaths, fps=original_fps) as video: video.write_videofile(output_path)
def infer_video( cfg, ckpt, video_path: str, score_threshold: float, dataset_type, output_path): assert pathlib.Path(video_path).is_file(),\ f"Did not find video: {video_path}" with tempfile.TemporaryDirectory() as cache_dir: input_image_dir = pathlib.Path(cache_dir, "input_images") input_image_dir.mkdir() with mp.VideoFileClip(video_path) as video: original_fps = video.fps dump_frames(video, input_image_dir) output_image_dir = pathlib.Path(cache_dir, "video_images") output_image_dir.mkdir(exist_ok=True) run_demo( cfg, ckpt, score_threshold, pathlib.Path(input_image_dir), output_image_dir, dataset_type) impaths = list(output_image_dir.glob("*.png")) impaths.sort(key=lambda impath: int(impath.stem)) impaths = [str(impath) for impath in impaths] # The commended out code belongs to the starter code, but is not working properly # with mp.ImageSequenceClip(impaths, fps=original_fps) as video: # video.write_videofile(output_path) # Fix. Adapted from https://theailearner.com/2018/10/15/creating-video-from-images-using-opencv-python/ img_array = [] size = (0,0) for filepath in impaths: img = cv2.imread(filepath) img_array.append(img) height, width, _ = img.shape size = (width, height) out = cv2.VideoWriter( output_path, cv2.VideoWriter_fourcc(*'mp4v'), original_fps, size ) for i in range(len(img_array)): out.write(img_array[i]) out.release()
def test_demo_funs(self, mocked_funB): print('mock before import the module') from demo import run_demo mocked_funB.return_value = {} run_demo() assert mocked_funB.called
def test_run_demo(self): assert demo.run_demo() == None
import os import sys from demo import run_demo if __name__ == '__main__': if len((sys.argv)) > 1: url = sys.argv[1] run_demo(url) str_run = "feature_extraction/extract_feature.py" os.system(str_run) else: print("Please input url")
def main(args=None): # dechrau log.info('peiriant: dechrau') # parser = OptionParser(usage="%prog [-v] [-q] [-d] [llinyn] [-i infile] [-o outfile]", version="%prog: fersiwn 1.0", add_help_option=False) parser = OptionParser(usage="%prog [-v] [-q] [-d] [-p] [-r] [llinyn] [-i infile]", version="%prog: fersiwn 0.1", add_help_option=False) parser.add_option("-d", "--demo", action="store_true", dest="demo", help="showan off") parser.add_option("-p", "--penillion", action="store_true", dest="demo_penillion", help="mwy o showan off") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="allbwn amleiriog") parser.add_option("-q", "--quiet", action="store_false", dest="verbose", help="allbwn cryno") parser.add_option("-r", "--rhyddiaith", action="store_true", dest="rhyddiaith", help="mewnbwn rhyddiaith") parser.add_option("-i", "--input", dest="infile", help="ffeil mewnbwn") parser.add_option("-h", "--help", action="help", help="cymorth") parser.set_defaults(verbose=True, demo=False, rhyddiaith=False) (options, args) = parser.parse_args() # dosrannu'r dewisiadau llinyn = '' if not args: args = sys.argv[1:] else: llinyn = args[0] # 1. llinyn unigol neu demos if llinyn: dad = Dadansoddwr() adro = dad.oes_cynghanedd( Llinell( llinyn ) ) if options.verbose: print adro else: print lliw.magenta(adro.cynghanedd) + ': ' + llinyn.strip() return # 2. demos if options.demo: import demo demo.run_demo(verbose=options.verbose) return if options.demo_penillion: import demo_penillion demo_penillion.run_demo(verbose=options.verbose) return # 3. darllen o ffeil if options.infile: # rhyddiaith (hac, ond ok) if options.rhyddiaith: with codecs.open(options.infile, "r", "utf-8") as f: s = f.read() br = s.split('.') br = [b.strip() for b in br] brawddegau = [] for b in br: if len(b) > 0: brawddegau.append( b + u'.') print('----------------------------------------') dad = Dadansoddwr() for b in brawddegau: geiriau = [Gair(s) for s in b.split(' ')] ns = 0 idx_ch = 0 idx_dd = 1 rhestr = [] llinellau = [] while idx_dd < len(geiriau): while idx_dd < len(geiriau) and sum([ g.nifer_sillau() for g in geiriau[idx_ch:idx_dd] ]) < 7: rhestr.append( geiriau[idx_dd] ) idx_dd = idx_dd + 1 while sum([ g.nifer_sillau() for g in geiriau[idx_ch:idx_dd] ]) > 7: rhestr.reverse() rhestr.pop() rhestr.reverse() idx_ch = idx_ch + 1 if geiriau[idx_dd-1].llinyn() not in cy.geiriau_gwan: llinellau.append( Llinell( geiriau[idx_ch:idx_dd] ) ) idx_ch = idx_ch + 1 for llinell in llinellau: adro = dad.oes_cynghanedd( llinell ) if not adro.cynghanedd in ['DIM','SAL']: if options.verbose: print adro else: print lliw.magenta(adro.cynghanedd) + '\t' + adro.llinell.llinyn() print('----------------------------------------') return # cerdd with open(options.infile) as f: rhestr_llinynnau = f.readlines() # creu rhestr llinellau llinellau = [] for s in rhestr_llinynnau: s.strip() if re.search(r'^#', s) or re.search(r'^\s*$', s): continue llinellau.append( Llinell(s) ) # allbwn # if options.verbose: # print('========================================') # for llinell in llinellau: # print llinell.llinyn() # print('========================================') # dadansoddi pob llinell yn unigol (beth am doddeidiau? Mae angen darganfod cysylltnod) dad = Dadansoddwr() adro_llinellau_unigol = [] for llinell in llinellau: adro = dad.oes_cynghanedd( llinell ) adro_llinellau_unigol.append(adro) # profi mesurau dad = DadansoddwrPennill() pennill = Pennill(llinellau) cyw = dad.oes_cywydd( pennill ) eng = dad.oes_englyn( pennill ) cyh = dad.oes_cyhydedd_nawban( pennill ) hat = dad.oes_hir_a_thoddaid( pennill ) dosb = None if cyw[0]: dosb = 'CYW' adro = cyw[1] elif eng[0]: dosb = 'ENG' adro = eng[1] elif cyh[0]: dosb = 'CYH' adro = cyh[1] elif hat[0]: dosb = 'HAT' adro = hat[1] else: dosb = 'DIM' adro = adro_llinellau_unigol # allbwn print('----------------------------------------') if dosb: print lliw.cyan( dosb ) if adro: for ad in adro: if options.verbose: if ad.cynghanedd == 'DIM': print lliw.magenta( ad.cynghanedd ) print ad.llinyn_acenion() print ad.llinell.llinyn() else: print ad else: ss = ad.cynghanedd + ': ' + ad.llinell.llinyn().strip() if ad.cynghanedd == 'DIM': print lliw.magenta( ss ) else: print ss print('----------------------------------------') # diwedd print "hwyl fawr...\n" time_str = time.strftime("%Y.%m.%d.%H.%M.%S") log.info('peiriant: diwedd')
destination_nonfight_directory = r'/home/danielshay2021/pose_daniel/train/NonFight' source=[fight_directory,nonfight_directory] destination=[destination_fight_directory,destination_nonfight_directory] for source_dir,dest_dir in zip(source,destination): index = 0 print("source is" + source_dir) print(os.listdir(source_dir)) for dir in os.listdir(source_dir): # vmeid_name = destination_fight_directory+'\\vid'+ str(index) #windows version (\) vid_dir = str(index) # linux version (/) Path( destination_fight_directory + '/' + vid_dir,).mkdir(parents=True, exist_ok=True) print("creating dir: " + vid_dir) frame_index = 0 source_dir_current = source_dir + '/' + dir + '/*' source_files=glob.glob(source_dir_current) dest_dir_current = dest_dir + '/' + vid_dir print("dest_dir_current " + dest_dir_current) frame_provider = ImageReader(source_files) print(frame_provider.file_names) track = 0 smooth=1 cpu=True height_size=256 run_demo(net, frame_provider,height_size,cpu, track, smooth,dest_dir_current) index +=1
def print_text(self, controller, sections_path, geo_path): run_demo(controller.day.get(), controller.time.get(), controller.street.get(), sections_path, geo_path)
def main(args=None): # dechrau log.info('peiriant: dechrau') # parser = OptionParser(usage="%prog [-v] [-q] [-d] [llinyn] [-i infile] [-o outfile]", version="%prog: fersiwn 1.0", add_help_option=False) parser = OptionParser( usage="%prog [-v] [-q] [-d] [-p] [-r] [llinyn] [-i infile]", version="%prog: fersiwn 0.1", add_help_option=False) parser.add_option("-d", "--demo", action="store_true", dest="demo", help="showan off") parser.add_option("-p", "--penillion", action="store_true", dest="demo_penillion", help="mwy o showan off") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="allbwn amleiriog") parser.add_option("-q", "--quiet", action="store_false", dest="verbose", help="allbwn cryno") parser.add_option("-r", "--rhyddiaith", action="store_true", dest="rhyddiaith", help="mewnbwn rhyddiaith") parser.add_option("-i", "--input", dest="infile", help="ffeil mewnbwn") parser.add_option("-h", "--help", action="help", help="cymorth") parser.set_defaults(verbose=True, demo=False, rhyddiaith=False) (options, args) = parser.parse_args() # dosrannu'r dewisiadau llinyn = '' if not args: args = sys.argv[1:] else: llinyn = args[0] # 1. llinyn unigol neu demos if llinyn: dad = Dadansoddwr() adro = dad.oes_cynghanedd(Llinell(llinyn)) if options.verbose: print adro else: print lliw.magenta(adro.cynghanedd) + ': ' + llinyn.strip() return # 2. demos if options.demo: import demo demo.run_demo(verbose=options.verbose) return if options.demo_penillion: import demo_penillion demo_penillion.run_demo(verbose=options.verbose) return # 3. darllen o ffeil if options.infile: # rhyddiaith (hac, ond ok) if options.rhyddiaith: with codecs.open(options.infile, "r", "utf-8") as f: s = f.read() br = s.split('.') br = [b.strip() for b in br] brawddegau = [] for b in br: if len(b) > 0: brawddegau.append(b + u'.') print('----------------------------------------') dad = Dadansoddwr() for b in brawddegau: geiriau = [Gair(s) for s in b.split(' ')] ns = 0 idx_ch = 0 idx_dd = 1 rhestr = [] llinellau = [] while idx_dd < len(geiriau): while idx_dd < len(geiriau) and sum( [g.nifer_sillau() for g in geiriau[idx_ch:idx_dd]]) < 7: rhestr.append(geiriau[idx_dd]) idx_dd = idx_dd + 1 while sum( [g.nifer_sillau() for g in geiriau[idx_ch:idx_dd]]) > 7: rhestr.reverse() rhestr.pop() rhestr.reverse() idx_ch = idx_ch + 1 if geiriau[idx_dd - 1].llinyn() not in cy.geiriau_gwan: llinellau.append(Llinell(geiriau[idx_ch:idx_dd])) idx_ch = idx_ch + 1 for llinell in llinellau: adro = dad.oes_cynghanedd(llinell) if not adro.cynghanedd in ['DIM', 'SAL']: if options.verbose: print adro else: print lliw.magenta( adro.cynghanedd) + '\t' + adro.llinell.llinyn( ) print('----------------------------------------') return # cerdd with open(options.infile) as f: rhestr_llinynnau = f.readlines() # creu rhestr llinellau llinellau = [] for s in rhestr_llinynnau: s.strip() if re.search(r'^#', s) or re.search(r'^\s*$', s): continue llinellau.append(Llinell(s)) # allbwn # if options.verbose: # print('========================================') # for llinell in llinellau: # print llinell.llinyn() # print('========================================') # dadansoddi pob llinell yn unigol (beth am doddeidiau? Mae angen darganfod cysylltnod) dad = Dadansoddwr() adro_llinellau_unigol = [] for llinell in llinellau: adro = dad.oes_cynghanedd(llinell) adro_llinellau_unigol.append(adro) # profi mesurau dad = DadansoddwrPennill() pennill = Pennill(llinellau) cyw = dad.oes_cywydd(pennill) eng = dad.oes_englyn(pennill) cyh = dad.oes_cyhydedd_nawban(pennill) hat = dad.oes_hir_a_thoddaid(pennill) dosb = None if cyw[0]: dosb = 'CYW' adro = cyw[1] elif eng[0]: dosb = 'ENG' adro = eng[1] elif cyh[0]: dosb = 'CYH' adro = cyh[1] elif hat[0]: dosb = 'HAT' adro = hat[1] else: dosb = 'DIM' adro = adro_llinellau_unigol # allbwn print('----------------------------------------') if dosb: print lliw.cyan(dosb) if adro: for ad in adro: if options.verbose: if ad.cynghanedd == 'DIM': print lliw.magenta(ad.cynghanedd) print ad.llinyn_acenion() print ad.llinell.llinyn() else: print ad else: ss = ad.cynghanedd + ': ' + ad.llinell.llinyn().strip() if ad.cynghanedd == 'DIM': print lliw.magenta(ss) else: print ss print('----------------------------------------') # diwedd print "hwyl fawr...\n" time_str = time.strftime("%Y.%m.%d.%H.%M.%S") log.info('peiriant: diwedd')