Ejemplo n.º 1
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)

    except:
        print("missing or invalid arguments")
        if os.path.isfile("configs/example.json"):
            config = process_config("configs/example.json")
        else:
            config = process_config("../configs/example.json")

    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])
    # create tensorflow session
    sess = tf.Session()
    # create your data generator
    data = DataGenerator(config)

    # create an instance of the model you want
    model = ExampleModel(config)
    # create tensorboard logger
    logger = Logger(sess, config)
    # create trainer and pass all the previous components to it
    trainer = ExampleTrainer(sess, model, data, config, logger)
    # load model if exists
    model.load(sess)
    # here you train your model
    trainer.train()
def run_multi():
    # Get the arguments
    args = get_args()
    config, _ = get_config_from_json(args.config)
    values_sn = config.exp.vals
    values_train = config.exp.vals
    values_init = config.exp.vals
    params = config.exp.params
    section = config.exp.section
    # Spectral Normalization
    for i in values_sn:
        # Mode
        for j in values_train:
            # Init
            for k in values_init:
                config[section][params[0]] = i
                config[section][params[1]] = j
                config[section][params[2]] = k
                config.exp.name = args.experiment + "_{}{}{}".format(int(i), int(j), int(k))
                process_config(config)
                create_dirs(
                    [
                        config.log.summary_dir,
                        config.log.checkpoint_dir,
                        config.log.step_generation_dir,
                        config.log.log_file_dir,
                        config.log.codebase_dir,
                    ]
                )
                # Copy the model code and the trainer code to the experiment folder
                run(config, args)
                tf.reset_default_graph()
Ejemplo n.º 3
0
def main():
    global config
    try:
        args = get_args()
        config = process_config(args.config)
        # args.config = 'test_example.json'
        print(args.config)
        print(config.learning_rate)
        print(config.display_step)
        print(config.checkpoint_dir)
        print(config.summary_dir)
        print(config.training_epochs)
    except:
        print("Missing argument")
        exit(0)
    # create_dirs([config.summary_dir, config.checkpoint_dir])  already created dirs

    data = input_data.read_data_sets("/tmp/data/", one_hot=True)

    # sess = tf.Session()
    with tf.Session() as sess:

        model = MnistLogisticModel(config)

        logger = Logger(sess, config)

        trainer = MnistLogisticTrainer(sess, model, data, config, logger)

        trainer.train()
Ejemplo n.º 4
0
 def __init__(self, cc_path, rc_path, ac_path):
     # Here comes all the initialization required
     # Initialize the models
     self.cc = process_config(cc_path)
     self.rc = process_config(rc_path)
     self.ac = process_config(ac_path)
     self.cae, self.c_s, self.rnn, self.r_s, self.actions, self.a_s = self.load_models(
         self.cc, self.rc, self.ac)
     self.current_frame = np.zeros((128, 128))
     # Create the video stream thread
     try:
         t = threading.Thread(target=self.getVideoData)
         t.start()
         print("thread started")
     except:
         print("Something went wrong trying to start getVideoData")
Ejemplo n.º 5
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)

    except:
        print("missing or invalid arguments")
        exit(0)
    os.environ['CUDA_VISIBLE_DEVICES'] = config.CUDA_VISIBLE_DEVICES
    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])
    # create tensorflow session
    sess = tf.Session()
    # create your data generator
    data = DataGenerator(config)

    # create an instance of the model you want
    model = AutoEncodingConv2dBNModel(config)
    # create tensorboard logger
    logger = Logger(sess, config)
    # create trainer and pass all the previous components to it
    trainer = MyModelTrainer(sess, model, data, config, logger)
    #load model if exists
    model.load(sess)
    # here you train your model
    trainer.train()
Ejemplo n.º 6
0
def main():
    try:
        args = get_args()
        config = process_config(args.config)

    except:
        print("missing or invalid arguments")
        exit(0)

    create_dirs([config.summary_dir, config.checkpoint_dir])

    sess = tf.Session()

    data = DataGenerator(config)

    model = mlp(config)

    logger = Logger(sess, config)

    trainer = ExampleTrainer(sess, model, data, config, logger)

    model.load(sess)
    #trainer파일을 확인하면 trainer.train()과 새로 작성한 trainer.test()의 차이를 확인할 수 있다.
    #y는 테스트데이터의 실제 ppa, result는 학습된 모델의 추정 ppa값을 리스트로 받아온다.
    #result는 세션의 return이 [1][데이터개수]의 2차원 리스트의 형태이고 [0][i]로 각 input의 결과를 확인할 수 있다
    y, result = trainer.test()
    cnt = 0
    print(result[0])
    for i in range(len(y)):
        #실제값-추측값을 실제값으로 나누어 오차10%내의 데이터의 수를 센다
        if (abs(y[i] - float(result[0][i])) / y[i] <= 0.1):
            cnt += 1
    print('10% 내외로 예측한 데이터는 ', cnt / len(y), '% 이다')
Ejemplo n.º 7
0
def generate_labels():
    # capture the config path from the run arguments then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)
    except ValueError:
        print("Missing or invalid arguments")
        exit(0)

    print('Creating the data loader...')
    data_loader = DataLoader(config.labels_generator.paths)
    data = data_loader.get_data()

    print('Creating the Preprocessor...')
    preprocessor = CorexPreprocessor(data, config)
    preprocessor.prepare_data()

    print('Loading and evaluating the Model...')
    model = CorexModel(config, preprocessor, load=True)
    trainer = CorexTrainer(model, preprocessor.get_data())
    top_docs_df = trainer.get_top_documents(
        config.labels_generator.evaluate.extract_topics,
        preprocessor.get_raw_corpus(),
        config.labels_generator.evaluate.extraction_quantile)
    top_docs_df.to_csv(config.labels_generator.paths.save_data_path,
                       index=False)
Ejemplo n.º 8
0
def main():
    arg_parser = argparse.ArgumentParser(description="")
    arg_parser.add_argument(
        'config', metavar='config_json_file',
        default=None, help="Configuration file in JSON format."
    )

    args = arg_parser.parse_args()

    # parse config file
    config = process_config(args.config)

    # Create the agent and pass all the configuration to it and run
    agent_class = globals()[config["agent"]]
    agent = agent_class(config)

    # visualize training set
    agent.visualize_set()
    
    # # train model
    agent.run()
    agent.finalize()
    
    # Create inference agent and pass the configuration to it and interpret
    iagent_class = globals()[config["inference_agent"]]
    iagent = iagent_class(config)
    
    # plot learning rate, accuracy, loss graphs and misclassified images with gradcam
    iagent.show_per_class_accuracy()
    iagent.plot_lr_graph()
    iagent.plot_accuracy_graph()
    iagent.plot_loss_graph()
    iagent.show_misclassified_images()
Ejemplo n.º 9
0
def main():
    # capture the config path from the run arguments
    # then process the json configration file
    config = process_config(
        'F:/deep_learning/relaynet_tensorflow/configs/relaynet.json')

    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])
    # create tensorflow session
    gpu_config = tf.ConfigProto()
    gpu_config.gpu_options.allow_growth = True
    sess = tf.Session(config=gpu_config)
    config.learning_rate = np.concatenate(
        (1e-1 * np.ones(20), 1e-2 * np.ones(20), 1e-2 * np.ones(20)))
    # network_fn = ReLayNet(10, config=config, scope='relaynet02')
    network_fn = ReLayNet(config=config)
    # create instance of the model you want
    model = ReLayNetModel(config, network_fn)
    # create your data generator
    data = RetinalDataset(config)
    # create tensorboard logger
    logger = Logger(sess, config)
    # create trainer and path all previous components to it
    trainer = ReLayNetTrainer(sess, model, data, config, logger)

    # here you train your model
    trainer.train()
Ejemplo n.º 10
0
def main(memory_frac, config):

    tf_config = tf.ConfigProto()
    tf_config.gpu_options.per_process_gpu_memory_fraction = memory_frac
    set_session(tf.Session(config=tf_config))
    if config is None:
        config_path = constants.LSTM_CONFIG
    else:
        config_path = config
    # process the json configuration file
    config = process_config(config_path)

    # create the experiments dirs
    create_dirs([
        config.callbacks.tensorboard_log_dir, config.callbacks.checkpoint_dir,
        config.callbacks.model_dir, config.callbacks.config_dir,
        config.callbacks.result_dir
    ])

    print('Create the data generator.')
    data_loader = LSTMDataLoader(config)

    print('Create the model.')
    model = LSTMModel(config)

    copyfile(inspect.getfile(model.__class__),
             os.path.join(config.callbacks.model_dir, "model.py"))
    copyfile(config_path,
             os.path.join(config.callbacks.config_dir, "config.json"))

    print('Create the trainer')
    trainer = LSTMTrainer(model.build_model(), data_loader, config)

    print('Start training the model.')
    trainer.train()
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)

    except:
        print("missing or invalid arguments")
        exit(0)

    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])
    # create tensorflow session
    sess = tf.Session()
    # create an instance of the model you want
    model = MyModel(config)
    # create your data generator
    data = DataGenerator(config)
    # create tensorboard logger
    logger = Logger(sess, config)
    # create trainer and pass all the previous components to it
    trainer = SimpleTrainer(sess, model, data, config, logger)
    saverExternal = tf.train.Saver(var_list=tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope='external'))
    saverExternal.restore(sess, "experiments/model_8/model8.ckpt_2")

    # here you train your model
    trainer.train()
    trainer.validate()
Ejemplo n.º 12
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        json_file = '../configs/example.json'
        # config = process_config(args.config)
        config = process_config(json_file)

    except:
        print("missing or invalid arguments")
        exit(0)

    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])
    # create tensorflow session
    sess = tf.compat.v1.Session()
    # create your data generator
    data = DataGenerator(config)
    data.generate_data()

    # create an instance of the model you want
    model = ExampleModel(config)
    # create tensorboard logger
    logger = Logger(sess, config)
    # create trainer and pass all the previous components to it
    trainer = ExampleTrainer(sess, model, data, config, logger)
    #load model if exists
    model.load(sess)
    # here you train your model
    trainer.train()
    # here you evaluate your model
    evaluator = Evaluator(trainer.sess, trainer.model, data, config, logger)
    evaluator.evaluate()
    evaluator.analysis_results()
Ejemplo n.º 13
0
def main():
    # capture the config path from the run arguments
    # then process the json configration file
    try:
        args = get_args()
        config = process_config(args.config)
    except:
        print("missing or invalid arguments")
        exit(0)

    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])
    # create tensorflow session
    sess = tf.Session()
    # create instance of the model you want
    model = CapsuleNet(config)
    # create your data generator
    data = MNISTLoader(config)
    # create tensorboard logger
    logger = Logger(sess, config)
    # create trainer and path all previous components to it
    trainer = CapsuleNetTrainer(sess, model, data, config, logger)

    # here you train your model
    trainer.train()
Ejemplo n.º 14
0
def main():
    # capture the config path from the run argments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)
    except Exception as err:
        print("Missing or invalid arguments {}".format(err))
        exit(0)

    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])
    # create tensorflow session
    sess = tf.Session()
    # create your data generator
    data_loader = MnistData(config)

    # create an instance of the model you want
    model = MnistModel(config, data_loader)
    # create tensorboard logger
    logger = Logger(sess, config)
    # create trainer and pass all the previous components to it
    trainer = MnistTrainer(sess, model, config, logger, data_loader)
    # load model if exists
    model.load(sess)
    # here you train your model
    trainer.train()
Ejemplo n.º 15
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration fill
    try:
        args = get_args()
        config = process_config(args.config)

        # create the experiments dirs
        create_dirs([config.callbacks.tensorboard_log_dir, config.callbacks.checkpoint_dir])

        print('Create the data generator.')
        data_loader = factory.create("data_loader."+config.data_loader.name)(config)

        print('Create the model.')
        model = factory.create("models."+config.model.name)(config)

        if config.skip_train!=True:
            print('Create the trainer')
            trainer = factory.create("trainers."+config.trainer.name)(model.model, data_loader.get_train_data(), config)

            print('Start training the model.')
            trainer.train()
        
        # evaluator = factory.create("evaluators."+config.evaluator.name)(model.model, data_loader.get_test_data(), config)
        # evaluator.evaluate()
        evaluator = factory.create("evaluators."+config.evaluator.name)(model.model, data_loader.get_test_data(), config)
        
        result, y = evaluator.evaluate()
        result_idx = np.argmax(result,axis=1)
        y_idx = np.argmax(y,axis=1)
        print(classification_report(result_idx, y_idx))
    except Exception as e:
        print(e)
        sys.exit(1)
Ejemplo n.º 16
0
def main(model_dir):
    tf_config = tf.ConfigProto()
    tf_config.gpu_options.allow_growth = True
    set_session(tf.Session(config=tf_config))

    config = os.path.join(model_dir, "config.json")
    config_path = config

    # process the json configuration file
    config = process_config(config_path)
    config.trainer.batch_size = 1

    print('Create the data generator.')
    data_loader = factory.create("data_loader." +
                                 config.data_loader.name)(config)

    print('Create the model.')
    model = factory.create("models." + config.model.name)(config)

    print('Create the trainer')
    trainer = BaseTrain(model.build_model(), data_loader, config)

    # checkpoint_path = os.path.join(constants.ROOT_FOLDER, config.callbacks.checkpoint_dir, config.exp.name + ".hdf5")
    checkpoint_path = os.path.join(model_dir, "model.hdf5")
    model.load(checkpoint_path)
    scores_dict = trainer.evaluate()
    for metric in scores_dict:
        open(os.path.join(model_dir, metric + ".txt"),
             "w").write(str(scores_dict[metric]))
def main():
    """
    capture the config path from the run arguments
    then processw the json configuration file
    """
    try:
        args = get_args()
        config = process_config(args.config)
    except FileNotFoundError as e:
        print('missing or invalid arguments')
        exit(0)
        return

    create_dirs([
        config.callbacks.tensorboard_log_dir, config.callbacks.checkpoint_dir
    ])

    print('Get dataframe from csv')
    train_df, test_df = get_df_from_config(config)
    train_df['class'] = train_df['class'].astype('str')
    train_df = train_df[['img_file', 'class']]
    test_df = test_df[['img_file']]

    print('Create model')
    model = Resnet50Model(config)

    print('Create trainer')
    trainer = Resnet50Trainer(model, train_df, config)

    print('Start training model')
    trainer.train_with_cv(k=4)
Ejemplo n.º 18
0
def main():
    # try:
    #     args = get_args()
    #     config = process_config(args.config)
    #
    # except:
    #     print("missing or invalid arguments")
    #     exit(0)
    config_file = "configs/config.json"
    config = process_config(config_file)
    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])

    # embed_path = "data/glove.trimmed.{}.npz".format(config.embedding_size)
    # config.embed_path = embed_path
    # vocab_path = "data/vocab.dat"
    # config.vocab_path = vocab_path

    # create tensorflow session
    sess = tf.Session()

    # create data generator
    data = DataGenerator(config)
    sequence_length = data.sequence_length()
    vocab_size = data.get_vocab_size()
    # create an instance of the model
    model = CNNClassifier(config, sequence_length, vocab_size)
    #load model if exists
    model.load(sess)
    # create tensorboard logger
    logger = Logger(sess, config)
    # create trainer and pass all the previous components to it
    trainer = Trainer(sess, model, data, config, logger)

    trainer.train()
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)
    except:
        print("missing or invalid arguments")
        exit(0)

    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])

    print('Create the data generator.')
    data_generator = DataGenerator(config)

    print('Create the model.')
    model = MultiLabelConvModel(config, data_generator.get_word_index())

    print('Create the trainer')
    trainer = MultiLabelConvModelTrainer(model.model,
                                         data_generator.get_train_data(),
                                         config)

    print('Start training the model.')
    trainer.train()

    print('Visualize the losses')
    trainer.visualize()
Ejemplo n.º 20
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)

    except:
        print("missing or invalid arguments")
        exit(0)

    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])
    # create your data generator
    data = DataGenerator(config)
    # create tensorflow session
    tf_config = tf.ConfigProto()
    tf_config.gpu_options.allow_growth = True
    sess = tf.Session(config=tf_config)
    K.set_session(sess)
    # create an instance of the model you want
    model = GolfBallModel(config, data)
    # load model if exists
    model.load(sess)
    # create tensorboard logger
    logger = Logger(sess, config)
    if config.do_training:
        # create trainer and pass all the previous components to it
        trainer = GolfBallTrainer(sess, model, data, config, logger)
        # here you train your model
        trainer.train()
    if config.do_predict:
        GolfBallPrediction(sess, model, data, config)
Ejemplo n.º 21
0
def main():

    try:
        args = get_args()
        config = process_config(args.config)

    except Exception as e:
        print("missing or invalid arguments")
        print(e)
        exit(0)

    create_dirs([config.summary_dir, config.checkpoint_dir])

    conf = tf.ConfigProto()
    conf.gpu_options.allow_growth = True
    sess = tf.Session(config=conf)

    with sess.as_default():

        data_loader = USegNetLoader(config)

        model = USegNetModel(data_loader, config)

        logger = DefinedSummarizer(
            sess,
            summary_dir=config.summary_dir,
            scalar_tags=[
                'train/loss_per_epoch', 'train/dice_per_epoch',
                'train/iou_per_epoch', 'eval/loss_per_epoch',
                'eval/dice_per_epoch', 'eval/iou_per_epoch'
            ])

        trainer = USegNetTrainer(sess, model, config, logger, data_loader)

        trainer.train()
Ejemplo n.º 22
0
def main():
    try:
        args = get_args()
        config = process_config(args.config)

    except:
        print("missing or invalid arguments")
        exit(0)

    create_dirs([config.summary_dir, config.checkpoint_dir])
    sess = tf.Session()

    data_loader = notMNISTDataLoaderNumpy(config)
    model = notMNISTModel(data_loader, config)
    logger = DefinedSummarizer(sess,
                               summary_dir=config.summary_dir,
                               scalar_tags=[
                                   'train/loss_per_epoch',
                                   'train/acc_per_epoch',
                                   'test/loss_per_epoch', 'test/acc_per_epoch',
                                   'val/acc_per_epoch', 'val/loss_per_epoch'
                               ])

    trainer = notMNISTTrainer(sess, model, config, logger, data_loader)
    trainer.train()
def main():
    # capture the config path from the run arguments
    # then process the json configuration fill
    try:
        args = get_args()
        config = process_config(args.config)

        amp, sr = librosa.load(config.predictor.predict_file_path, sr=8000)
        amp = audio_norm(amp)  # normalize
        if amp.shape[0] < config.model.duration * sr:
            # 왼쪽 오른쪽 똑같은 크기로 reflect
            amp = np.pad(amp,
                         int(np.ceil((10 * sr - amp.shape[0]) / 2)),
                         mode='reflect')
        amp = amp[:config.model.duration * sr]
        data = np.expand_dims(amp, axis=0)
        data = np.expand_dims(data, axis=-1)

        print('Create the model.')
        model = factory.create("models." + config.model.name)(config)

        predictor = factory.create("predictors." + config.predictor.name)(
            model.model, data, config)
        predictor.predict()
        sys.stdout.flush()
    except Exception as e:
        print(e)
        sys.stdout.flush()
Ejemplo n.º 24
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)
    except:
        print("missing or invalid arguments")
        exit(0)

    # create the experiments dirs
    create_dirs([
        config.callbacks.tensorboard_log_dir, config.callbacks.checkpoint_dir
    ])

    print('Create the data generator.')
    data_loader = ConvFashionMnistDataLoader(config)

    print('Create the model.')
    model = ConvMnistModel(config)

    print('Create the trainer')
    trainer = FashionMnistModelTrainer(model.model,
                                       data_loader.get_train_data(), config)

    print('Start training the model.')
    trainer.train()
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)
    except:
        print("missing or invalid arguments")
        exit(0)

    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir, config.visual_dir])

    models = {
        'noise_model1': NoiseModel.build_model1(config),
        'noise_model2': NoiseModel.build_model2(config),
        'noise_model3': NoiseModel.build_model3(config)
    }

    print('Create the data generator.')
    data_generator = DataLoader(config)

    print('Create the model.')
    model = models[config.exp_name]

    print('Create the trainer')
    trainer = NoiseModelTrainer(model, data_generator.get_train_data(), config)

    print('Start training the model.')
    trainer.train()

    print('Visualize the losses')
    trainer.visualize()
Ejemplo n.º 26
0
def main():
    args = get_args()
    config = process_config(args.config)

    # create the experiments dirs
    create_dirs([config.cache_dir, config.model_dir,
        config.log_dir, config.img_dir])

    # logging to the file and stdout
    logger = get_logger(config.log_dir, config.exp_name)
    
    # Intialize wandb model
    run = wandb.init(project="SemiSupervised", config=args)
    run.save()
    args.run_name = wandb.run.name

    # fix random seed to reproduce results
    random.seed(config.random_seed)
    logger.info('Random seed: {:d}'.format(config.random_seed))

    if config.method in ['src', 'jigsaw', 'rotate']:
        model = AuxModel(config, logger)
    else:
        raise ValueError("Unknown method: %s" % config.method)
    
    src_loader, val_loader = get_train_val_dataloader(config.datasets.src)
    # test_loader = get_test_dataloader(config.datasets.test)
    test_loader = None

    tar_loader = None
    if config.datasets.get('tar', None):
        tar_loader = get_target_dataloader(config.datasets.tar)

    if config.mode == 'train':
        model.train(src_loader, tar_loader, val_loader, test_loader)
Ejemplo n.º 27
0
def main():
    # Capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)

        Model = import_class(args.config, "model")
        Trainer = import_class(args.config, "trainer")
    except:
        print("Missing or invalid arguments")
        exit(0)

    # Create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])
    # Create a tensorflow session
    sess = tf.InteractiveSession()
    # Create an instance of the model specified
    model = Model(config)
    # Load model if it exists
    model.load(sess)
    # Create the data generator
    data = DataGenerator(config)
    # Create tensorboard logger
    logger = Logger(sess, config)
    # Create trainer and pass all the previous components to it
    trainer = Trainer(sess, model, data, config, logger)

    # Train the model
    trainer.train()
    print("Training complete!")
    sess.close()
Ejemplo n.º 28
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)

    except Exception:
        print("missing or invalid arguments")
        raise
    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])
    # create tensorflow session
    configSess = tf.ConfigProto(allow_soft_placement=True,
                                log_device_placement=False)
    configSess.gpu_options.allow_growth = True
    sess = tf.Session(config=configSess)
    # create your data generator
    data = DataGenerator(config)
    # create an instance of the model you want
    try:
        ModelInit = all_models[config.model]
        model = ModelInit(config)
    except AttributeError:
        raise
    # create tensorboard logger
    logger = Logger(sess, config)
    # create trainer and pass all the previous components to it
    trainer = NetworkTrainer(sess, model, data, config, logger)
    # load model if exists
    model.load(sess, args.checkpoint_nb)
    # here you train your model
    trainer.train()
Ejemplo n.º 29
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)

    except Exception as e:
        print("missing or invalid arguments %s" % e)
        exit(0)

    os.environ["CUDA_VISIBLE_devices"] = config.gpu
    import tensorflow as tf

    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])
    # create tensorflow session
    gpuconfig = tf.ConfigProto(allow_soft_placement=True,
                               log_device_placement=False)
    gpuconfig.gpu_options.visible_device_list = config.gpu
    sess = tf.Session(config=gpuconfig)
    # create your data generator
    data = DataGenerator(config)

    # create an instance of the model you want
    model = invariant_basic(config, data)
    # create trainer and pass all the previous components to it
    trainer = Trainer(sess, model, data, config)
    # load model if exists
    model.load(sess)
    # here you train your model
    trainer.train()
Ejemplo n.º 30
0
def main():
    try:
        args = get_args()
        config = process_config(args.config)
    except:
        print("missing or invalid arguments")
        exit(0)

    # config = process_config('configs/imc.json')
    create_dirs([config.summary_dir, config.checkpoint_dir])
    sess = tf.Session()
    # create instance of the model you want
    model = IMCModel(config)
    # load model if exist
    model.load(sess)
    # create your data generator
    imc_data = DataGenerator(config)

    # create tensorboard logger
    logger = Logger(sess, config)
    # create trainer and path all previous components to it
    trainer = IMCTrainer(sess, model, imc_data, config, logger)
    # # here you train your model
    trainer.train()

    # trainer.recognize()
    recogflag = input("recognize your image now? image in {} Y/N".format(
        config.dir_af))
    if recogflag == "Y" or recogflag == "y" or recogflag == '':
        recognize_image(config.dir_af, config.checkpoint_dir, config.graph_dir,
                        config.image_size)
    else:
        print("Process end!")
Ejemplo n.º 31
0
    def __init__(self, config="configs/urbanSound.json"):
        if isinstance(config, str):
            config = process_config(config)
        super(SoundDataLoader, self).__init__(config)

        # get the absolute path of the datastore
        currentDrive, path = os.path.splitdrive(os.getcwd())
        self.dataFolder = os.path.join(
            currentDrive, os.path.sep.join(path.split(os.path.sep)[:-1]),
            "Datastore", "Acoustical")

        self.attributes = pd.read_csv(os.path.join(self.dataFolder,
                                                   self.config.testplan),
                                      sep=";")
        if not os.path.isfile(
                os.path.join(self.dataFolder, self.config.features)):
            print("features.csv not found...")
            print("\nLoading features...")
            self.createFeatureFrame(self.dataFolder)

        else:
            self.features = pd.read_csv(os.path.join(self.dataFolder,
                                                     self.config.features),
                                        sep=";")
        self.data = None
        pd.options.mode.chained_assignment = None  # default='warn'
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)

    except:
        print("missing or invalid arguments")
        exit(0)

    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])
    # create tensorflow session
    sess = tf.Session()
    # create an instance of the model you want
    model = MyModel(config)
    # create your data generator
    data = DataGenerator(config)
    # create tensorboard logger
    logger = Logger(sess, config)
    # create trainer and pass all the previous components to it
    trainer = SimpleTrainer(sess, model, data, config, logger)

    # here you train your model
    trainer.train()
    trainer.validate()
Ejemplo n.º 33
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)
    except:
        print("missing or invalid arguments")
        exit(0)

    # create the experiments dirs
    create_dirs([config.tensorboard_log_dir, config.checkpoint_dir, "val_test"])

    print('Create the data generator.')
    if hasattr(config, "data_set"):
        if config.data_set == "face_data_77":
            data_loader = FaceLandmark77DataLoader(config)
        else:
            data_loader = SimpleMnistDataLoader(config)
    else:
        data_loader = SimpleMnistDataLoader(config)

    print('Create the model.')
    if hasattr(config, "model_name"):
        if config.model_name == "mobile_net":
            model = MobileNetV2Model(config)
        else:
            model = SimpleMnistModel(config)
    else:
        model = SimpleMnistModel(config)

    print(model.model.input_names)
    print([out.op.name for out in model.model.outputs])
    return

    if hasattr(config, "best_checkpoint"):
        model.load(config.best_checkpoint)
        frozen_graph = freeze_session(K.get_session(),
                                      output_names=[out.op.name for out in model.model.outputs])

        ckpt_path = Path(config.best_checkpoint)
        tf.train.write_graph(frozen_graph, str(ckpt_path.parent), ckpt_path.with_suffix(".pb").name, as_text=False)
Ejemplo n.º 34
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)
    except:
        print("missing or invalid arguments")
        exit(0)

    # create the experiments dirs
    create_dirs([config.tensorboard_log_dir, config.checkpoint_dir])

    print('Create the data generator.')
    if hasattr(config, "data_set"):
        if config.data_set == "face_data_77":
            data_loader = FaceLandmark77DataLoader(config)
        else:
            data_loader = SimpleMnistDataLoader(config)
    else:
        data_loader = SimpleMnistDataLoader(config)

    print('Create the model.')
    if hasattr(config, "model_name"):
        if config.model_name == "mobile_net":
            model = MobileNetV2Model(config)
        else:
            model = SimpleMnistModel(config)
    else:
        model = SimpleMnistModel(config)

    print('Create the trainer')
    trainer = SimpleMnistModelTrainer(model.model, data_loader, config)

    print('Start training the model.')
    trainer.train()