def main(): parser = argparse.ArgumentParser(description='Baseline') parser.add_argument('--conf_path', type=str, metavar='conf_path', help='input the path of config file') parser.add_argument('--id', type=int, metavar='experiment_id', help='Experiment ID') args = parser.parse_args() option = Option(args.conf_path) option.manualSeed = args.id + 1 option.experimentID = option.experimentID + "{:0>2d}_repeat".format( args.id) if option.dataset in ["cifar100"]: generator = Generator(option) elif option.dataset in ["imagenet"]: generator = Generator_imagenet(option) else: assert False, "invalid data set" experiment = ExperimentDesign(generator, option) experiment.run()
def set_color_player(): """ Choose the player color (mode Player vs AI). """ screen = pygame.display.set_mode((770, 770)) options = [Option("Black", (750, 430), screen, r_text), Option("White", (750, 480), screen, r_text), Option("Return", (750, 750), screen, r_text)] run = True color = None while run: pygame.event.pump() background = pygame.image.load('./img/MenuBG.jpg') screen.blit(background, (0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: run = False for option in options: if option.surf.collidepoint(pygame.mouse.get_pos()): option.hover = True if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: run, color = option.func(option.text) else: option.hover = False option.draw() for option in options: option.hover = bool(option.surf.collidepoint(pygame.mouse.get_pos())) option.draw() pygame.display.update() return color
def __init__(self): self.screen = pygame.display.set_mode((770, 770)) self.options = [ Option("Player VS Player", (750, 430), self.screen, gameplay.load_p_vs_p), Option("Player VS IA", (750, 480), self.screen, gameplay.load_p_vs_ai), Option("Quit", (750, 750), self.screen, gameplay.r_false) ]
def __init__(self, options=None, conf_path=None): self.settings = options or Option(conf_path) super(Generator_imagenet, self).__init__() self.init_size = self.settings.img_size // 4 self.l1 = nn.Sequential( nn.Linear(self.settings.latent_dim, 128 * self.init_size**2)) self.conv_blocks0_0 = CategoricalConditionalBatchNorm2d(1000, 128) self.conv_blocks1_0 = nn.Conv2d(128, 128, 3, stride=1, padding=1) self.conv_blocks1_1 = CategoricalConditionalBatchNorm2d(1000, 128, 0.8) self.conv_blocks1_2 = nn.LeakyReLU(0.2, inplace=True) self.conv_blocks2_0 = nn.Conv2d(128, 64, 3, stride=1, padding=1) self.conv_blocks2_1 = CategoricalConditionalBatchNorm2d(1000, 64, 0.8) self.conv_blocks2_2 = nn.LeakyReLU(0.2, inplace=True) self.conv_blocks2_3 = nn.Conv2d(64, self.settings.channels, 3, stride=1, padding=1) self.conv_blocks2_4 = nn.Tanh() self.conv_blocks2_5 = nn.BatchNorm2d(self.settings.channels, affine=False)
def main(argv): opt = Option.validate(argv) analyzer = Analyzer() listener = Listener(analyzer, opt.hdfs_path, opt.local_path, opt.roll_size) auth = OAuthHandler(opt.consumer_key, opt.consumer_secret) auth.set_access_token(opt.access_token_key, opt.access_token_secret) if not os.path.exists(Util.TMP_DIR + '/' + Util.TWEETS): os.makedirs(Util.TMP_DIR + '/' + Util.TWEETS) if not os.path.exists(Util.TMP_DIR + '/' + Util.WORDCLOUD): os.makedirs(Util.TMP_DIR + '/' + Util.WORDCLOUD) # create new local paths if opt.local_path: if not os.path.exists(opt.local_path + '/' + Util.TWEETS): os.makedirs(opt.local_path + '/' + Util.TWEETS) if not os.path.exists(opt.local_path + '/' + Util.WORDCLOUD): os.makedirs(opt.local_path + '/' + Util.WORDCLOUD) stream = Stream(auth, listener) stream.filter(track=opt.keywords)
def game_intro(): intro = True animation = pygame.Rect(0, 0, 50, 50) while intro: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit(0) if animation.x > 800 & animation.y > 800: animation.x += 0 animation.y += 0 animation.width += 0 else: animation.x += 1 animation.y += 1 animation.width += 1 options = [ Option("1.Start game", (100, 450), screen), Option("2.Exit game", (100, 500), screen) ] # x y for option in options: if option.rect.collidepoint(pygame.mouse.get_pos()): option.cover = True else: option.cover = False option.draw(screen) # Choose option by mouse if options[0].rect.collidepoint( pygame.mouse.get_pos()) & pygame.mouse.get_pressed()[0]: break if options[1].rect.collidepoint( pygame.mouse.get_pos()) & pygame.mouse.get_pressed()[0]: sys.exit(0) keys = pygame.key.get_pressed() if keys[pygame.K_1]: break if keys[pygame.K_2]: sys.exit(0) pygame.draw.rect(screen, (120, 0, 0), animation) pygame.event.pump() pygame.display.flip() pygame.display.update() clock.tick(200)
def main(): parser = argparse.ArgumentParser(description='Baseline') parser.add_argument('conf_path', type=str, metavar='conf_path', help='input batch size for training (default: 64)') args = parser.parse_args() option = Option(args.conf_path) save_path = option.save_path experimentID = option.experimentID for i in range(0,1): option.experimentID = experimentID + "{:0>2d}_repeat".format(i + 1) option.save_path = save_path option.manualSeed = i + 1 experiment = ExperimentDesign(option) best_top1, best_top5 = experiment.run() experiment.logger.handlers = []
def main(): parser = argparse.ArgumentParser(description='Baseline') parser.add_argument('conf_path', type=str, metavar='conf_path', help='input batch size for training (default: 64)') parser.add_argument('id', type=int, metavar='experiment_id', help='Experiment ID') args = parser.parse_args() option = Option(args.conf_path) option.manualSeed = args.id + 1 option.experimentID = option.experimentID + "{:0>2d}_repeat".format( args.id + 1) experiment = ExperimentDesign(option) experiment.run()
def main(): parser = argparse.ArgumentParser(description='Baseline') parser.add_argument('conf_path', type=str, metavar='conf_path', help='input batch size for training (default: 64)') args = parser.parse_args() option = Option(args.conf_path) experiment = ExperimentDesign(option) experiment.run()
def __init__(self, _trade_list, _current_window): #Calling super <Tab> super().__init__() #Trades self.trades = deepcopy(_trade_list) #Options image self.options_image = Option() #Get the current secondary window self.cw = _current_window #Content self.groupbox_date = None self.date_option_label = None self.checkbox_startdate = None self.button_startdate = None self.textbox_startdate = None self.checkbox_enddate = None self.button_enddate = None self.textbox_enddate = None #Attributes self.startDate = None self.endDate = None self.currentlySelectedCalendar = None #loading the UI self.__load_ui__() #Load dates on textboxes self.__load_dates_on_textbox__() #Load current options image startDate = str(self.trades[0][4]) endDate = str(self.trades[-1][4]) startDate = startDate[:-6] endDate = endDate[:-6] #Set Default values and current values of Option obj self.options_image.setValues( Date(int(startDate[3:5]), int(startDate[0:2]), int(startDate[-4:])), Date(int(endDate[3:5]), int(endDate[0:2]), int(endDate[-4:])), 'D', [True, True, True, False])
def __init__(self, options=None): self.settings = options or Option() self.checkpoint = None self.train_loader = None self.test_loader = None self.model = None self.optimizer_state = None self.trainer = None self.start_epoch = 0 self.test_input = None self.visualize = vs.Visualization(self.settings.save_path) self.logger = vs.Logger(self.settings.save_path) self.prepare()
def __init__(self): self.settings = Option() self.checkpoint = None self.data_loader = None self.model = None self.trainer = None self.seg_opt_state = None self.fc_opt_state = None self.aux_fc_state = None self.start_epoch = 0 self.model_analyse = None self.visualize = vs.Visualization(self.settings.save_path) self.logger = vs.Logger(self.settings.save_path) self.prepare()
def __init__(self, options=None, conf_path=None): super(Generator, self).__init__() self.settings = options or Option(conf_path) self.label_emb = nn.Embedding(self.settings.nClasses, self.settings.latent_dim) self.init_size = self.settings.img_size // 4 self.l1 = nn.Sequential( nn.Linear(self.settings.latent_dim, 128 * self.init_size**2)) self.conv_blocks0 = nn.Sequential(nn.BatchNorm2d(128), ) self.conv_blocks1 = nn.Sequential( nn.Conv2d(128, 128, 3, stride=1, padding=1), nn.BatchNorm2d(128, 0.8), nn.LeakyReLU(0.2, inplace=True), ) self.conv_blocks2 = nn.Sequential( nn.Conv2d(128, 64, 3, stride=1, padding=1), nn.BatchNorm2d(64, 0.8), nn.LeakyReLU(0.2, inplace=True), nn.Conv2d(64, self.settings.channels, 3, stride=1, padding=1), nn.Tanh(), nn.BatchNorm2d(self.settings.channels, affine=False))
def __init__(self, options=None, conf_path=None): self.settings = options or Option(conf_path) self.checkpoint = None self.train_loader = None self.test_loader = None self.model = None self.optimizer_state = None self.trainer = None self.start_epoch = 0 self.test_input = None os.environ['CUDA_DEVICE_ORDER'] = "PCI_BUS_ID" os.environ['CUDA_VISIBLE_DEVICES'] = self.settings.visible_devices self.settings.set_save_path() self.logger = self.set_logger() self.settings.paramscheck(self.logger) self.visualize = vs.Visualization(self.settings.save_path, self.logger) self.tensorboard_logger = vs.Logger(self.settings.save_path) self.prepare()
def __init__(self, generator=None, options=None, conf_path=None): self.settings = options or Option(conf_path) self.generator = generator self.train_loader = None self.test_loader = None self.model = None self.model_teacher = None self.optimizer_state = None self.trainer = None self.start_epoch = 0 self.test_input = None self.unfreeze_Flag = True os.environ['CUDA_DEVICE_ORDER'] = "PCI_BUS_ID" os.environ['CUDA_VISIBLE_DEVICES'] = self.settings.visible_devices self.settings.set_save_path() self.logger = self.set_logger() self.settings.paramscheck(self.logger) self.prepare()
def train(): # read BFM face model # transfer original BFM model to our model if not os.path.isfile('./BFM/BFM_model_front.mat'): transferBFM09() with tf.Graph().as_default() as graph: # training options args = parse_args() opt = Option(model_name=args.model_name) opt.data_path = [args.data_path] opt.val_data_path = [args.val_data_path] # load training data into queue train_iterator = load_dataset(opt) # create reconstruction model model = Reconstruction_model(opt) # send training data to the model model.set_input(train_iterator) # update model variables with training data model.step(is_train = True) # summarize training statistics model.summarize() # several training stattistics to be saved train_stat = model.summary_stat train_img_stat = model.summary_img train_op = model.train_op photo_error = model.photo_loss lm_error = model.landmark_loss id_error = model.perceptual_loss # load validation data into queue val_iterator = load_dataset(opt,train=False) # send validation data to the model model.set_input(val_iterator) # only do foward pass without updating model variables model.step(is_train = False) # summarize validation statistics model.summarize() val_stat = model.summary_stat val_img_stat = model.summary_img # initialization saver, train_writer,val_writer, sess = restore_weights_and_initialize(opt) # freeze the graph to ensure no new op will be added during training sess.graph.finalize() # training loop for i in range(opt.train_maxiter): _,ph_loss,lm_loss,id_loss = sess.run([train_op,photo_error,lm_error,id_error]) print('Iter: %d; lm_loss: %f ; photo_loss: %f; id_loss: %f\n'%(i,np.sqrt(lm_loss),ph_loss,id_loss)) # summarize training stats every <train_summary_iter> iterations if np.mod(i,opt.train_summary_iter) == 0: train_summary = sess.run(train_stat) train_writer.add_summary(train_summary,i) # summarize image stats every <image_summary_iter> iterations if np.mod(i,opt.image_summary_iter) == 0: train_img_summary = sess.run(train_img_stat) train_writer.add_summary(train_img_summary,i) # summarize validation stats every <val_summary_iter> iterations if np.mod(i,opt.val_summary_iter) == 0: val_summary,val_img_summary = sess.run([val_stat,val_img_stat]) val_writer.add_summary(val_summary,i) val_writer.add_summary(val_img_summary,i) # # save model variables every <save_iter> iterations if np.mod(i,opt.save_iter) == 0: saver.save(sess,os.path.join(opt.model_save_path,'iter_%d.ckpt'%i))
def demo(): # input and output folder args = parse_args() image_path = 'input' save_path = 'output' if not os.path.exists(save_path): os.makedirs(save_path) img_list = glob.glob(image_path + '/' + '*.png') img_list +=glob.glob(image_path + '/' + '*.jpg') # read BFM face model # transfer original BFM model to our model if not os.path.isfile('./BFM/BFM_model_front.mat'): transferBFM09() # read standard landmarks for preprocessing images lm3D = load_lm3d() n = 0 # build reconstruction model with tf.Graph().as_default() as graph: with tf.device('/cpu:0'): opt = Option(is_train=False) opt.batch_size = 1 opt.pretrain_weights = args.pretrain_weights FaceReconstructor = Face3D() images = tf.placeholder(name = 'input_imgs', shape = [opt.batch_size,224,224,3], dtype = tf.float32) if args.use_pb and os.path.isfile('network/FaceReconModel.pb'): print('Using pre-trained .pb file.') graph_def = load_graph('network/FaceReconModel.pb') tf.import_graph_def(graph_def,name='resnet',input_map={'input_imgs:0': images}) # output coefficients of R-Net (dim = 257) coeff = graph.get_tensor_by_name('resnet/coeff:0') else: print('Using pre-trained .ckpt file: %s'%opt.pretrain_weights) import networks coeff = networks.R_Net(images,is_training=False) # reconstructing faces FaceReconstructor.Reconstruction_Block(coeff,opt) face_shape = FaceReconstructor.face_shape_t face_texture = FaceReconstructor.face_texture face_color = FaceReconstructor.face_color landmarks_2d = FaceReconstructor.landmark_p recon_img = FaceReconstructor.render_imgs tri = FaceReconstructor.facemodel.face_buf with tf.Session() as sess: if not args.use_pb : restore_weights(sess,opt) print('reconstructing...') for file in img_list: n += 1 print(n) # load images and corresponding 5 facial landmarks img,lm = load_img(file,file.replace('png','txt').replace('jpg','txt')) # preprocess input image input_img,lm_new,transform_params = align_img(img,lm,lm3D) coeff_,face_shape_,face_texture_,face_color_,landmarks_2d_,recon_img_,tri_ = sess.run([coeff,\ face_shape,face_texture,face_color,landmarks_2d,recon_img,tri],feed_dict = {images: input_img}) # reshape outputs input_img = np.squeeze(input_img) face_shape_ = np.squeeze(face_shape_, (0)) face_texture_ = np.squeeze(face_texture_, (0)) face_color_ = np.squeeze(face_color_, (0)) landmarks_2d_ = np.squeeze(landmarks_2d_, (0)) if not is_windows: recon_img_ = np.squeeze(recon_img_, (0)) # save output files if not is_windows: savemat(os.path.join(save_path,file.split(os.path.sep)[-1].replace('.png','.mat').replace('jpg','mat')),{'cropped_img':input_img[:,:,::-1],'recon_img':recon_img_,'coeff':coeff_,\ 'face_shape':face_shape_,'face_texture':face_texture_,'face_color':face_color_,'lm_68p':landmarks_2d_,'lm_5p':lm_new}) save_obj(os.path.join(save_path,file.split(os.path.sep)[-1].replace('.png','_mesh.obj').replace('.jpg','_mesh.obj')),face_shape_,tri_,np.clip(face_color_,0,255)/255) # 3D reconstruction face (in canonical view)
config_parser.add_task("decode", xnmt_decode.options) config_parser.add_task("evaluate", xnmt_evaluate.options) # Tweak the options to make config files less repetitive: # - Delete evaluate:evaluator, replace with exp:eval_metrics # - Delete decode:hyp_file, evaluate:hyp_file, replace with exp:hyp_file # - Delete train:model, decode:model_file, replace with exp:model_file config_parser.remove_option("evaluate", "evaluator") config_parser.remove_option("decode", "trg_file") config_parser.remove_option("evaluate", "hyp_file") config_parser.remove_option("train", "model_file") config_parser.remove_option("decode", "model_file") experiment_options = [ Option("model_file", default_value="<EXP>.mod", help_str="Location to write the model file"), Option("hyp_file", default_value="<EXP>.hyp", help_str="Location to write decoded output for evaluation"), Option("out_file", default_value="<EXP>.out", help_str="Location to write stdout messages"), Option("err_file", default_value="<EXP>.err", help_str="Location to write stderr messages"), Option( "eval_metrics", default_value="bleu", help_str="Comma-separated list of evaluation metrics (bleu/wer/cer)" ),
from training_corpus import * from loss_tracker import * from preproc import SentenceFilterer from options import Option, OptionParser, general_options import model_globals import serializer import xnmt_decode import xnmt_evaluate from evaluator import PPLScore from tee import Tee ''' This will be the main class to perform training. ''' options = [ Option("dynet-mem", int, required=False), Option("dynet-gpu-ids", int, required=False), Option( "dev_every", int, default_value=0, force_flag=True, help_str="dev checkpoints every n sentences (0 for only after epoch)"), Option("batch_size", int, default_value=32, force_flag=True), Option("batch_strategy", default_value="src"), Option("training_corpus"), Option("corpus_parser"), # Option("train_filters", list, required=False, help_str="Specify filtering criteria for the training data"), # Option("dev_filters", list, required=False, help_str="Specify filtering criteria for the development data"), Option("model_file"), Option("save_num_checkpoints",
def main(): cwd = Path(__file__).resolve().parent default_config_path = cwd / 'config.json' parser = ArgumentParser(prog=f'IZ*ONE Mail Shelter v{__version__}') parser.add_argument( '-c', '--config', default=default_config_path, type=Path, metavar='<file>', help='Specify a JSON-format text file to read user configurations from.' ) args = parser.parse_args() # Parse user config config_path = args.config print(f'{Fore.YELLOW}==>{Fore.RESET}{Style.BRIGHT} Parsing configuration') # Validate config root = Options('root') root.add(Option('mail_path', required=True)) root.add(Option('embed_css', default=False, type=bool)) root.add(Option('css_path', default='../css')) root.add(Option('image_to_base64', default=False, type=bool)) root.add(Option('image_path', default='img')) root.add( Option('timeout', default=5, type=(int, float), validator=lambda t: t >= 0)) root.add( Option('max_retries', default=3, type=int, validator=lambda i: i >= 0)) root.add(Option('finish_hook', validator=lambda s: len(s) > 0)) profile = Options('profile', required=True) for k in Profile.valid_keys(): profile.add(Option(k, required=Profile.is_required_key(k))) root.add(profile) try: config = EasyDict(json.loads(config_path.read_text(encoding='utf-8'))) root.parse_options(config) except FileNotFoundError as e: print(f"❌️ Configuration file '{e.filename}' missing!") return -1 except (KeyError, TypeError, ValueError) as e: print(f"❌️ {e}") return -2 # Print parsed config print(json.dumps(config, indent=4)) # File containing local last mail timestamp head_path = cwd / 'HEAD' head = bytes_to_datetime(head_path.read_bytes()) if head_path.is_file( ) else datetime.fromisoformat('2018-10-29T20:00') print(f'📢 {Fore.CYAN}{Style.BRIGHT}HEAD -> {Fore.GREEN}{head.isoformat()}') # Index file index_path = cwd / 'INDEX' index = pickle.loads( index_path.read_bytes()) if index_path.is_file() else set() def execute_handler(*args): finish_hook = config.finish_hook if finish_hook is None: return returncode = _execute_handler(finish_hook, 'IZ*ONE Mail Shelter', *args) if returncode != 0: print( f'⚠️ The return code of finish hook is non-zero ({hex(returncode)})' ) # requests session options s_opts = {'timeout': config.timeout, 'max_retries': config.max_retries} # IZ*ONE Private Mail client app = IZONEMail(Profile({k: v for k, v in config.profile.items() if v}), **s_opts) # Check if profile is valid print( f'\n{Fore.BLUE}==>{Fore.RESET}{Style.BRIGHT} Retrieving user information' ) user = app.get_user() print( f'{user.id} / {user.nickname} / {user.gender} / {user.country_code} / {user.birthday}' ) # Retrieve the list of new mails print( f'\n{Fore.MAGENTA}==>{Fore.RESET}{Style.BRIGHT} Retrieving new mails from inbox' ) new_mails = [] caught_up = False page = 1 while True: inbox = app.get_inbox(page) for mail in inbox: if mail.id in index: caught_up = True break print( f'💌 Found new mail {mail.id}: {mail.member.name} / {mail.subject} / {mail.received}' ) new_mails.append(mail) # If we caught up or this inbox was the last one, break the loop if caught_up or not inbox.has_next_page: break page += 1 if not new_mails: print('Already up-to-date.') execute_handler(0) return 0 n_total = len(new_mails) print(f'{n_total} new mails are available.') # Start downloading mails print(f'\n{Fore.GREEN}==>{Fore.RESET}{Style.BRIGHT} Downloading new mails') # Create mail composer mail_composer = MailComposer() mail_composer += InsertMailHeader() mail_composer += RemoveAllJS() mail_composer += RemoveAllStyleSheet() mail_composer += EmbedStyleSheet( ) if config.embed_css else DumpStyleSheetToLocal(config.css_path) mail_composer += ConvertAllImagesToBase64( **s_opts) if config.image_to_base64 else DumpAllImagesToLocal(**s_opts) n_downloaded = 0 n_skipped = 0 try: # Start from the oldest one pbar = tqdm(reversed(new_mails), total=n_total) for mail in pbar: pbar.set_description(f'Processing {mail.id}') # Build file path and check if already exists mail_path = config.mail_path.format_map({ 'member_id': mail.member.id, 'member_name': mail.member.name, 'mail_id': mail.id, 'received': mail.received, 'subject': mail.subject, }) mail_file = Path(mail_path) if mail_file.is_file(): tqdm.write( f"⚠️ File '{mail_file}' already exists! Skipping...") head = mail.received index.add(mail.id) n_skipped += 1 continue # Fetch mail detail mail_detail = app.get_mail_detail(mail) # Compose mail content content = mail_composer(user, mail, mail_detail, mail_file) # Save to specified path mail_file.parent.mkdir(parents=True, exist_ok=True) mail_file.write_text(content, encoding='utf-8') # Update HEAD head = mail.received # Update INDEX index.add(mail.id) n_downloaded += 1 finally: print(f'\n{Fore.CYAN}==>{Fore.RESET}{Style.BRIGHT} Summary') print( f'Total: {n_total} / Downloaded: {n_downloaded} / Skipped: {n_skipped}' ) head_path.write_bytes(datetime_to_bytes(head)) # index_path.write_bytes(pickle.dumps(index)) print( f'📢 {Fore.CYAN}{Style.BRIGHT}HEAD -> {Fore.GREEN}{head.isoformat()}' ) print('\n🎉 IZ*ONE Mail Shelter is up to date.') execute_handler(n_downloaded) return 0
class OptionTab(QtWidgets.QTabWidget): def __init__(self, _trade_list, _current_window): #Calling super <Tab> super().__init__() #Trades self.trades = deepcopy(_trade_list) #Options image self.options_image = Option() #Get the current secondary window self.cw = _current_window #Content self.groupbox_date = None self.date_option_label = None self.checkbox_startdate = None self.button_startdate = None self.textbox_startdate = None self.checkbox_enddate = None self.button_enddate = None self.textbox_enddate = None #Attributes self.startDate = None self.endDate = None self.currentlySelectedCalendar = None #loading the UI self.__load_ui__() #Load dates on textboxes self.__load_dates_on_textbox__() #Load current options image startDate = str(self.trades[0][4]) endDate = str(self.trades[-1][4]) startDate = startDate[:-6] endDate = endDate[:-6] #Set Default values and current values of Option obj self.options_image.setValues( Date(int(startDate[3:5]), int(startDate[0:2]), int(startDate[-4:])), Date(int(endDate[3:5]), int(endDate[0:2]), int(endDate[-4:])), 'D', [True, True, True, False]) #Load the Graphical Content def __load_ui__(self): spacing_left = 10 self.groupbox_date = QtWidgets.QGroupBox(self) self.groupbox_date.setGeometry(QtCore.QRect(0, 0, 175, 400)) gridLayout = QtWidgets.QGridLayout() #TextLabel self.date_option_label = QtWidgets.QLabel(self) self.date_option_label.setGeometry( QtCore.QRect(spacing_left, 25, 150, 25)) self.date_option_label.setText("Date options: ") #Group-StartDate-Checkbox self.checkbox_startdate = QtWidgets.QCheckBox(self) self.checkbox_startdate.setGeometry( QtCore.QRect(spacing_left, 50, 100, 25)) self.checkbox_startdate.setText("Start date") #Group-StartDate-threeDotButton self.button_startdate = QtWidgets.QPushButton(self) self.button_startdate.setGeometry( QtCore.QRect(spacing_left + 75, 55, 50, 20)) self.button_startdate.setText("Pick from calendar") #Group-StartDate-textbox self.textbox_startdate = QtWidgets.QLineEdit(self) self.textbox_startdate.setGeometry( QtCore.QRect(spacing_left + 150, 55, 75, 20)) self.textbox_startdate.setText("dd/mm/YYYY") self.textbox_startdate.setReadOnly(True) #Group-EndDate-Checkbox self.checkbox_enddate = QtWidgets.QCheckBox(self) self.checkbox_enddate.setGeometry( QtCore.QRect(spacing_left, 75, 100, 25)) self.checkbox_enddate.setText("Last date") #Group-EndDate-threeDotButton self.button_enddate = QtWidgets.QPushButton(self) self.button_enddate.setGeometry( QtCore.QRect(spacing_left + 75, 80, 50, 20)) self.button_enddate.setText("Pick from calendar") #Group-EndDate-textbox self.textbox_enddate = QtWidgets.QLineEdit(self) self.textbox_enddate.setGeometry( QtCore.QRect(spacing_left + 150, 80, 75, 20)) self.textbox_enddate.setText("dd/mm/YYYY") self.textbox_enddate.setReadOnly(True) #Separator self.separator_0 = QtWidgets.QLabel(self) self.separator_0.setGeometry(QtCore.QRect(spacing_left, 90, 150, 25)) self.separator_0.setText("_______________________") #RadioButtons self.radiobutton_custom_date = QtWidgets.QRadioButton(self) self.radiobutton_custom_date.setGeometry( QtCore.QRect(spacing_left + 150, 100, 75, 20)) self.radiobutton_custom_date.setText("Custom date filter") self.radiobutton_real_money_gain = QtWidgets.QRadioButton(self) self.radiobutton_real_money_gain.setGeometry( QtCore.QRect(spacing_left + 150, 110, 75, 20)) self.radiobutton_real_money_gain.setText("Real money gain filter") #Separator self.separator_1 = QtWidgets.QLabel(self) self.separator_1.setGeometry(QtCore.QRect(spacing_left, 120, 150, 25)) self.separator_1.setText("_______________________") #TextLabel self.select_time_window = QtWidgets.QLabel(self) self.select_time_window.setGeometry( QtCore.QRect(spacing_left, 130, 150, 25)) self.select_time_window.setText("Select Window time: ") #Combobox self.combobox_time_window = QtWidgets.QComboBox(self) self.combobox_time_window.setGeometry( QtCore.QRect(spacing_left, 140, 150, 25)) self.combobox_time_window.addItem('Default') self.combobox_time_window.addItem('Daily') self.combobox_time_window.addItem('Weekly') self.combobox_time_window.addItem('Monthly') self.combobox_time_window.setCurrentIndex(0) #ApplyButton self.button_apply = QtWidgets.QPushButton(self) self.button_apply.setGeometry( QtCore.QRect(spacing_left + 75, 150, 50, 20)) self.button_apply.setText("Apply") #ResetButton self.button_reset = QtWidgets.QPushButton(self) self.button_reset.setGeometry( QtCore.QRect(spacing_left + 125, 150, 50, 20)) self.button_reset.setText("Reset") #Calendar self.cal_frame = QtWidgets.QMainWindow() self.cal_frame.resize(325, 325) self.cal_frame.setWindowTitle("Calendar: Pick a day") self.cal_frame.setMinimumSize(QtCore.QSize(325, 305)) self.cal_frame.setMaximumSize(QtCore.QSize(325, 305)) self.cal = QtWidgets.QCalendarWidget(self.cal_frame) self.cal.setGeometry(0, 0, 325, 300) self.cal.setGridVisible(False) self.__setMinAndMaxDateOnCalendar__() self.cal.clicked[QtCore.QDate].connect(self.getDate) gridLayout.addWidget(self.date_option_label) gridLayout.addWidget(self.checkbox_startdate) gridLayout.addWidget(self.button_startdate) gridLayout.addWidget(self.textbox_startdate) gridLayout.addWidget(self.checkbox_enddate) gridLayout.addWidget(self.button_enddate) gridLayout.addWidget(self.textbox_enddate) gridLayout.addWidget(self.separator_0) gridLayout.addWidget(self.radiobutton_custom_date) gridLayout.addWidget(self.radiobutton_real_money_gain) gridLayout.addWidget(self.separator_1) gridLayout.addWidget(self.select_time_window) gridLayout.addWidget(self.combobox_time_window) gridLayout.addWidget(self.button_apply) gridLayout.addWidget(self.button_reset) self.groupbox_date.setLayout(gridLayout) self.groupbox_date.show() #Event Connection self.button_startdate.clicked.connect(self.__openCalendar_startDate__) self.button_enddate.clicked.connect(self.__openCalendar_endDate__) self.checkbox_startdate.stateChanged.connect( self.__on_start_date_checked__) self.checkbox_enddate.stateChanged.connect( self.__on_end_date_checked__) self.button_apply.clicked.connect(self.__apply_changes_to_options__) self.button_reset.clicked.connect(self.__reset_changes_to_options__) #Setting checkbox and radiobuttons self.checkbox_startdate.setChecked(True) self.checkbox_enddate.setChecked(True) self.radiobutton_custom_date.setChecked(True) self.radiobutton_real_money_gain.setChecked(False) #Momentaneous disabling self.radiobutton_real_money_gain.setEnabled(False) self.combobox_time_window.setEnabled(True) #Enable and disable line based on checking - StartDate def __on_start_date_checked__(self): self.button_startdate.setEnabled(self.checkbox_startdate.isChecked()) self.textbox_startdate.setEnabled(self.checkbox_startdate.isChecked()) self.radiobutton_custom_date.setChecked(True) #Enable and disable line based on checking - EndDate def __on_end_date_checked__(self): self.button_enddate.setEnabled(self.checkbox_enddate.isChecked()) self.textbox_enddate.setEnabled(self.checkbox_enddate.isChecked()) self.radiobutton_custom_date.setChecked(True) #Load dates from list of trades def __load_dates_on_textbox__(self): self.textbox_startdate.setText(str(self.trades[0][4])) self.textbox_enddate.setText(str(self.trades[-1][4])) #Open the calendar - startDate #Set Min and Max date on calendar def __setMinAndMaxDateOnCalendar__(self): startDate = str(self.trades[0][4]) endDate = str(self.trades[-1][4]) startDate = startDate[:-6] endDate = endDate[:-6] self.cal.setMinimumDate( QtCore.QDate(int(startDate[-4:]), int(startDate[3:5]), int(startDate[0:2]))) self.cal.setMaximumDate( QtCore.QDate(int(endDate[-4:]), int(endDate[3:5]), int(endDate[0:2]))) #Open the calendar - startDate def __openCalendar_startDate__(self): self.currentlySelectedCalendar = 0 self.cal_frame.show() #Open the calendar - endDate def __openCalendar_endDate__(self): self.currentlySelectedCalendar = 1 self.cal_frame.show() #Apply the current Gui state to Option Obj def __apply_changes_to_options__(self): startdate = self.textbox_startdate.text()[:-6] enddate = self.textbox_enddate.text()[:-6] cbox_value = self.combobox_time_window.currentText() time_window = None if cbox_value == 'Default': time_window = 'D' elif cbox_value == 'Daily': time_window = 'd' elif cbox_value == 'Weekly': time_window = 'w' elif cbox_value == 'Monthly': time_window = 'm' year_s = int(startdate[-4:].replace("/", "")) month_s = int(startdate[3:5].replace("/", "")) day_s = int(startdate[0:2].replace("/", "")) year_e = int(enddate[-4:].replace("/", "")) month_e = int(enddate[3:5].replace("/", "")) day_e = int(enddate[0:2].replace("/", "")) new_date_start = Date(month_s, day_s, year_s) new_date_end = Date(month_e, day_e, year_e) #Get GUI values guistate = [] guistate.append(self.checkbox_startdate.isChecked()) guistate.append(self.checkbox_enddate.isChecked()) guistate.append(self.radiobutton_custom_date.isChecked()) guistate.append(self.radiobutton_real_money_gain.isChecked()) #load new values self.options_image.setValues(new_date_start, new_date_end, time_window, guistate) #Change list of trades self.cw.reload_tabs(self.options_image) #Reset the current Gui state to Option Obj def __reset_changes_to_options__(self): #load new values self.options_image.setValues(self.options_image.startDate_d, self.options_image.endDate_d, self.options_image.time_window_d) #Change list of trades self.cw.reload_tabs(self.options_image) #Get date from calendar widget def getDate(self): date = self.cal.selectedDate() if (self.currentlySelectedCalendar == 0): date_str = str(date.month()) + "/" + str(date.day()) + "/" + str( date.year()) + " 00:00" self.textbox_startdate.setText(date_str) else: date_str = str(date.month()) + "/" + str(date.day()) + "/" + str( date.year()) + " 23:59" self.textbox_enddate.setText(date_str) self.cal_frame.hide() #Load a particular state of GUI by specifying the options def load_state(self, _options): print("Loading previous state of options:") self.textbox_startdate.setText( str(_options.startDate.m) + "/" + str(_options.startDate.d) + "/" + str(_options.startDate.y) + " 00:00") self.textbox_enddate.setText( str(_options.endDate.m) + "/" + str(_options.endDate.d) + "/" + str(_options.endDate.y) + " 23:59") if _options.time_window == 'D': self.combobox_time_window.setCurrentIndex( self.combobox_time_window.findText('Default')) elif _options.time_window == 'd': self.combobox_time_window.setCurrentIndex( self.combobox_time_window.findText('Daily')) elif _options.time_window == 'm': self.combobox_time_window.setCurrentIndex( self.combobox_time_window.findText('Monthly')) elif _options.time_window == 'w': self.combobox_time_window.setCurrentIndex( self.combobox_time_window.findText('Weekly')) #Setting checkbox and radiobuttons self.checkbox_startdate.setChecked(_options.state_checkbox_startDate) self.checkbox_enddate.setChecked(_options.state_checkbox_endDate) self.radiobutton_custom_date.setChecked( _options.state_radiobutton_custom) self.radiobutton_real_money_gain.setChecked( _options.state_radiobutton_realmoneygain)
config_parser.add_task("decode", xnmt_decode.options) config_parser.add_task("evaluate", xnmt_evaluate.options) # Tweak the options to make config files less repetitive: # - Delete evaluate:evaluator, replace with exp:eval_metrics # - Delete decode:hyp_file, evaluate:hyp_file, replace with exp:hyp_file # - Delete train:model, decode:model_file, replace with exp:model_file config_parser.remove_option("evaluate", "evaluator") config_parser.remove_option("decode", "trg_file") config_parser.remove_option("evaluate", "hyp_file") config_parser.remove_option("train", "model_file") config_parser.remove_option("decode", "model_file") experiment_options = [ Option("model_file", default_value="<EXP>.mod", help_str="Location to write the model file"), Option("hyp_file", default_value="<EXP>.hyp", help_str="Location to write decoded output for evaluation"), Option("out_file", default_value="<EXP>.out", help_str="Location to write stdout messages"), Option("err_file", default_value="<EXP>.err", help_str="Location to write stderr messages"), Option("eval_only", bool, default_value=False, help_str="Skip training and evaluate only"), Option(
# coding: utf-8 from output import * from serializer import * import codecs import sys from options import OptionParser, Option from io import open ''' This will be the main class to perform decoding. ''' options = [ Option("dynet-mem", int, required=False), Option("dynet-gpu-ids", int, required=False), Option("model_file", force_flag=True, required=True, help_str="pretrained (saved) model path"), Option("src_file", help_str="path of input src file to be translated"), Option("trg_file", help_str="path of file where expected trg translatons will be written"), Option("max_src_len", int, required=False, help_str="Remove sentences from data to decode that are longer than this on the source side"), Option("input_format", default_value="text", help_str="format of input data: text/contvec"), Option("post_process", default_value="none", help_str="post-processing of translation outputs: none/join-char/join-bpe"), Option("beam", int, default_value=1), Option("max_len", int, default_value=100), ] NO_DECODING_ATTEMPTED = u"@@NO_DECODING_ATTEMPTED@@" def xnmt_decode(args, model_elements=None): """ :param model_elements: If None, the model will be loaded from args.model_file. If set, should
import argparse import sys from evaluator import BLEUEvaluator, WEREvaluator, CEREvaluator from options import Option, OptionParser from xnmt_decode import NO_DECODING_ATTEMPTED options = [ Option("ref_file", help_str="path of the reference file"), Option("hyp_file", help_str="path of the hypothesis trg file"), Option("evaluator", default_value="bleu", help_str="Evaluation metrics (bleu/wer/cer)") ] def read_data(loc_): """Reads the lines in the file specified in loc_ and return the list after inserting the tokens """ data = list() with open(loc_) as fp: for line in fp: t = line.split() data.append(t) return data def xnmt_evaluate(args): """"Returns the eval score (e.g. BLEU) of the hyp sents using reference trg sents """ if args.evaluator == "bleu":
from sys import argv import requests from options import Option from tabulate import tabulate req = requests.get( 'https://api.skypicker.com/locations?type=subentity&term=GB&locale=en-US&location_types=airport&sort=name&limit=20' ) opter = Option(req.json()) head = ['Name'] data = [opter.structure_names()] if '--help' in argv: f = open('./static/help.txt', 'r') msg = f.read() print(msg) f.close() if '--iata' in argv: head.append('IATA') data.append(opter.structure_iata()) if '--cities' in argv: head.append('City') data.append(opter.structure_cities()) if '--coords' in argv: head.append('Longitude') head.append('Lattitude')
from embedder import * from attender import * from input import * from encoder import * from decoder import * from translator import * from model_params import * from loss_tracker import * from serializer import * from options import Option, OptionParser, general_options ''' This will be the main class to perform training. ''' options = [ Option("dynet-mem", int, required=False), Option("dynet-gpu-ids", int, required=False), Option("eval_every", int, default_value=10000, force_flag=True), Option("batch_size", int, default_value=32, force_flag=True), Option("batch_strategy", default_value="src"), Option("train_src"), Option("train_trg"), Option("dev_src"), Option("dev_trg"), Option( "max_src_len", int, required=False, help_str= "Remove sentences from training/dev data that are longer than this on the source side" ),
hdfs_path=None, local_path=None): tweet_files = os.listdir(tmp_tweet_dir) for tf in tweet_files: if hdfs_path: hadoopy.put(tmp_tweet_dir + '/' + tf, hdfs_path + Util.TWEETS + '/' + tf[-24:-4] + '.csv') if local_path: shutil.copy(tmp_tweet_dir + '/' + tf, local_path + Util.TWEETS + '/' + tf[-24:-4] + '.csv') os.remove(tmp_tweet_dir + '/' + tf) wordcloud_files = os.listdir(tmp_wordcloud_dir) for wf in wordcloud_files: if hdfs_path: hadoopy.put(tmp_wordcloud_dir + '/' + wf, hdfs_path + Util.WORDCLOUD + '/' + wf[-24:-4] + '.csv') if local_path: shutil.copy( tmp_wordcloud_dir + '/' + wf, local_path + Util.WORDCLOUD + '/' + wf[-24:-4] + '.csv') os.remove(tmp_wordcloud_dir + '/' + wf) # our program's main entry point if __name__ == '__main__': opt = Option.validate(sys.argv[1:]) main(opt) # main(sys.argv[1:])