Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--pretrain",
                        help="option for pre-Training",
                        action="store_true")
    parser.add_argument("--train",
                        help="option for Training",
                        action="store_true")
    parser.add_argument(
        "--test",
        help=
        "option for Test with Image ex) python main.py --test -i image_name",
        action="store_true")
    parser.add_argument("-i", "--image", help="input Image for Testing")
    args = parser.parse_args()

    if args.pretrain:
        pretrain = PreTrain()
        pretrain.training()

    elif args.train:
        train = Train()
        train.training()

    elif args.test:
        if (args.image):
            img = cv2.resize(cv2.imread(args.image), (448, 448))
            test = Test()
            test.predict(img)
        else:
            print("please input image with -i or --image")

    return 1
Exemplo n.º 2
0
def main():

    try:
        # sys.argv[1] should give the absolute path to the input file
        # parse the file and process the command
        input_file = sys.argv[1]
        extension = input_file.split('.')
        # checking file type
        if extension[1] == 'txt':
            # reading input file
            with open(input_file) as f:
                lines = f.readlines()
            # Object instantiation
            train = Train()
            # calling arrival and departure station method
            result = train.arrival_departure_station(lines)
            # display arrival and departure station
            for i in range(0, len(result), 3):
                print(result[i])
                print(result[i + 1])
                print(result[i + 2])
        else:
            print('Invalid input format')
    except Exception as e:
        print(str(e))
Exemplo n.º 3
0
 def main():
     print "Creating Train File..."
     Data.CreateDataFile("mails-train", "mails-train.txt")
     print "Initializing Train File..."
     trainingSet = Data.LoadFile("mails-train.txt")
     print "Creating Test File..."
     Data.CreateDataFile("mails-test", "mails-test.txt")
     print "Initializing Test File..."
     testSet = Data.LoadFile("mails-test.txt")
     print "Extracting Classes.."
     classes = Train.ExtractClasses(trainingSet)
     print "Training NBC..."
     vocabulary, prior, condprob = Train.TrainMultinomialNaiveBayes(
         classes, trainingSet)
     print "Testing Accuracy..."
     percentage = Test.Accuracy(classes, vocabulary, prior, condprob,
                                testSet)
     print "The percentage of correct predictions is ", 100 * percentage, "percent."
     print "Get Random Document..."
     testDocument = Data.GetDocument(testSet)
     print "Do A Time Measurement of the Application of the NBC..."
     print "The time is took to do a single application of the NBC on a document is", Test.TimeMeasure(
         classes, vocabulary, prior, condprob, testDocument), "seconds."
     print "Applying NBC on Document..."
     topClass, score = Classify.ApplyMultinomialNaiveBayes(
         classes, vocabulary, prior, condprob, testDocument['document'])
Exemplo n.º 4
0
    def single_execution(config):
        """
        Executes training/prediction for the config as a single individual process
        :param config: config object
        :return:
        """

        os.environ["CUDA_VISIBLE_DEVICES"] = str(config.default_gpu)[-1]

        from data_processing import CDRSInferenceData, Dataset
        from train import Train
        from predict import Predict

        if config.cdrs_inference:
            dataset = CDRSInferenceData(config)
        else:
            dataset = Dataset(config)

        # training
        if config.train:
            print("Training")
            train = Train(config, dataset)
            train.train()

        # prediction
        else:
            print("Prediction")
            pred = Predict(config, dataset)
            pred.predict()

        return
Exemplo n.º 5
0
def sumbit(test_name, output_filename, model2):
    tr = Train()
    df = pd.read_csv(test_name)
    im_names = df['im_name']
    prediction_x = []
    prediction_y = []
    im_name = []
    for im_name_ in im_names:
        print(im_name_)
        first_model_output = tr.predict_normal(
            model,
            '/home/hikkav/hack/data/eye_tracking/test_images/' + im_name_,
            thr=True)
        print(first_model_output)
        X = transform(
            np.array(first_model_output).reshape(1, -1),
            'scalertask2_1.pickle')
        pred = model2.predict(X)
        pred = detransform(pred, 'scalertask2_2.pickle')
        pred = np.array(list(map(int, pred[0])))
        print(pred)
        prediction_x.append(pred[0])
        prediction_y.append(pred[1])

    df['im_name'] = im_names
    df['x'] = prediction_x
    df['y'] = prediction_y
    df.to_csv(output_filename, index=False)
Exemplo n.º 6
0
def main():
    sess = tf.Session()
    data = u.return_data()
    model = BiLSTM(u.Config, data[2])
    logger = Logger(sess, u.Config)
    trainer = Train(sess, model, data, u.Config, logger)
    trainer.train()
Exemplo n.º 7
0
def make_overall():
    tr = Train()
    df = load_vectors()
    tr.make_data(
        model,
        df,
    )
Exemplo n.º 8
0
 def TestGame1():
     modelO = ModelTwoDensesSigmoidMasked()
     modelX = ModelTwoDensesSigmoidMasked()
     trainer = Train(modelO, modelX)
     modelO.LoadWeights('O2.h5')
     modelX.LoadWeights('X2.h5')
     trainer.PlayGame(Game(), lambda g: print(g))
Exemplo n.º 9
0
def main():
    if config.action == "train":
        dataset = Dataset(config.trainDatasetFolder, config.npzTrainDatasetPath, config.outputImageSize)
        if os.path.exists(config.npzTrainDatasetPath):
            dataset.extract_train_target_images()
            print('Npz compressed dataset already saved at ', config.npzTrainDatasetPath)
        else:
            # Convert the raw image dataset into npz compressed format and extract
            dataset.process()
        # Plot a few sample images to verify data processing went well.
        dataset.plot_sample_input_target_images(5)

        trainer = Train(dataset, config.epochs, config.batchSize, config.checkpointDir, config.logsDir)
        trainer.start()
    elif config.action == "test":
        evaluator = Evaluator(config.modelPath)
        evaluator.predict(config.test_image)
    else:
        valid_dataset = Dataset(config.validDatasetFolder, config.npzValidDatasetPath, config.outputImageSize)
        if os.path.exists(config.npzValidDatasetPath):
            valid_dataset.extract_train_target_images()
            print('Npz compressed dataset already saved at ', config.npzTrainDatasetPath)
        else:
            # Convert the raw image dataset into npz compressed format and extract
            valid_dataset.process()
        evaluator = Evaluator(config.modelPath)
        evaluator.test_all_val_images(valid_dataset)
Exemplo n.º 10
0
def main():
    random.seed(42)
    dataset = get_dataset()
    train = Train(dataset, get_target_column_from_argparser(dataset),
                  get_ntree_from_argparser())
    model_performance = train.execute()
    print_model_performance(model_performance)
Exemplo n.º 11
0
def main():
    cudnn.benchmark = True
    torch.set_default_tensor_type('torch.FloatTensor')

    n_classes = 11
    epoch = 0
    lr = 5e-4
    wd = ''
    bs = 16
    maxepoch = 30

    model = torch.nn.DataParallel(model, device_ids=range(torch.cuda.device_count()))
    model.cuda()
    optimizer = torch.optim.Adam(model.parameters(), lr)

    criterion_weight = 1/np.log(1.02 + hist)
    criterion_weight[0] = 0
    criterion = nn.NLLLoss(Variable(torch.from_numpy(criterion_weight).float().cuda()))
    print('{}Using weighted criterion{}!!!'.format(CP_Y, CP_C))

    train = Train(model, data_loader_train, optimizer, criterion, lr, wd)

    while epoch <= maxepoch:
        train_error = train.forward()
        
        epoch += 1
Exemplo n.º 12
0
    def start_new_game(self, chosen_crew):
        """Start new game.

        Args:
            chosen_crew (str): The chosen initial crew.
        """
        self.train = Train()

        self.camera_ctrl = CameraController()
        self.camera_ctrl.set_controls(self.train)

        self.journal = Journal()

        self.team = Crew()
        self.team.gen_default(chosen_crew)

        self.common_ctrl = CommonController(self.train.parts, self.team.chars)

        # build game world
        self.world = World()
        self.world.generate_location(600, chosen_crew)
        self.current_block = self.world.prepare_next_block()

        self.common_ctrl.set_controls()

        self.char_gui = CharacterGUI()
        self.res_gui = ResourcesGUI()
        self.main_menu.show_start_button()
        self.dollars = 300

        self.scenario = Scenario()
Exemplo n.º 13
0
def model_parameters():
    from train import Train
    model = Train().model

    print('========== Begin someting about model parameters:')
    print("Encoder Model All Parameters:", sum(p.nelement() for p in model.encoder.parameters()))
    print("Decoder Model All Parameters:", sum(p.nelement() for p in model.decoder.parameters()))
    print("Reduce State Model All Parameters:", sum(p.nelement() for p in model.reduce_state.parameters()))
    print("Total Model All Parameters:", sum(p.nelement() for p in model.parameters()))
    print()
    print("Encoder Model Grad Parameters:", sum(p.nelement() for p in model.encoder.parameters() if p.requires_grad))
    print("Encoder LSTM Grad Parameters:", sum(p.nelement() for p in model.encoder.lstm.parameters() if p.requires_grad))
    print("Decoder Model Grad Parameters:", sum(p.nelement() for p in model.decoder.parameters() if p.requires_grad))
    print("Decoder LSTM Grad Parameters:", sum(p.nelement() for p in model.decoder.lstm.parameters() if p.requires_grad))
    print("Decoder Attention Grad Parameters:",
          sum(p.nelement() for p in model.decoder.attention.parameters() if p.requires_grad))
    print("Reduce State Model Grad Parameters:",
          sum(p.nelement() for p in model.reduce_state.parameters() if p.requires_grad))
    print("Total Model All Parameters:", sum(p.nelement() for p in model.parameters() if p.requires_grad))
    print()
    for name, param in model.named_parameters():
        if param.requires_grad:
            print(name, param.data.shape, param.nelement())
    print()

    print('========== Begin someting about model embedding layer:')
    print(model.encoder.embed.weight[:10])
    print()
Exemplo n.º 14
0
    def fit(self, epochs):
        train_loss_history = []
        test_loss_history = []
        epoch_history = {
            "train": train_loss_history,
            "test": test_loss_history
        }

        self.train_object = Train("./speed_data/FSM/preprocessed_471_2017.csv",
                                  self.weekday, self.ids.train_start.text,
                                  self.ids.train_end.text,
                                  self.ids.test_start.text,
                                  self.ids.test_end.text,
                                  int(self.popup.ids.time_step.text), 0,
                                  self.daypart)
        for i in range(epochs):
            temp_train, temp_test = self.train_object.fit(
                int(self.popup.ids.batch.text))
            epoch_history["train"].append(temp_train)
            epoch_history["test"].append(temp_test)
            self.manager.screens[1].update_results(epoch_history, i + 1,
                                                   epochs)
            self.manager.screens[1].ids.progress.value = i + 1
        self.train_object.save_estimations(file_name)
        self.manager.screens[2].get_dataframe()
        self.manager.screens[1].ids.results.disabled = False
        self.manager.screens[1].ids.home.disabled = False
Exemplo n.º 15
0
def main(config):
    # TODO: construct metrics
    # DONE: output all variables value to pickle, so that we can use it to initialize other models.
    train = Train(config,DataFeeder)
    gb = GraphBuilder(config)
    model_dict = gb.build_graph()
    train.train(model_dict)
Exemplo n.º 16
0
    def __init__(self, exp_fol):
        self.exp_fol = pathlib.Path(exp_fol)
        if not self.exp_fol.exists():
            raise FileNotFoundError("The given experiment folder path does not exists: {}".format(str(self.exp_fol)))

        train_config = self.exp_fol.joinpath("train_config.yaml")
        Train.__init__(self, config_file=str(train_config))
Exemplo n.º 17
0
 def generate_train(self, init_point, init_port, dest_point, dest_port,
                    **kwargs):
     '''
         Generate train only.'''
     _new_train = None
     length = 1 if kwargs.get('length') is None else kwargs.get('length')
     if self.capacity_enterable(init_point, dest_point):
         init_segment = ((None, None), (init_point, init_port)) \
             if not init_point.track_by_port.get(init_port)\
             else (( init_point.track_by_port[init_port]
                     .shooting_point(point=init_point),
                     init_point.track_by_port[init_port]
                     .shooting_port(point=init_point)),
                   (init_point, init_port))
         dest_segment = ((dest_point, dest_port), (None, None)) \
             if not dest_point.track_by_port.get(dest_port)\
             else (( dest_point.track_by_port[dest_port]
                     .shooting_point(point=dest_point),
                     dest_point.track_by_port[dest_port]
                     .shooting_port(point=dest_point)),
                   (dest_point, dest_port))
         init_track = self.get_track_by_point_port_pairs(
             init_segment[0][0], init_segment[0][1], init_segment[1][0],
             init_segment[1][1])
         if not init_track:
             _new_train = Train(system=self,
                                init_segment=init_segment,
                                dest_segment=dest_segment,
                                max_spd=random.choice(self.spd_container),
                                max_acc=random.choice(self.acc_container),
                                max_dcc=random.choice(self.dcc_container),
                                length=length)
         elif init_track.is_Occupied:
             print('\tWarning: cannot generate train: track is occupied. \
                 Hold new train for track availablity.')
         elif not init_track.routing:
             _new_train = Train(system=self,
                                init_segment=init_segment,
                                dest_segment=dest_segment,
                                max_spd=random.choice(self.spd_container),
                                max_acc=random.choice(self.acc_container),
                                max_dcc=random.choice(self.dcc_container),
                                length=length)
         elif Train.sign_MP(init_segment) == init_track.sign_routing(
                 init_track.routing):
             _new_train = Train(system=self,
                                init_segment=init_segment,
                                dest_segment=dest_segment,
                                max_spd=random.choice(self.spd_container),
                                max_acc=random.choice(self.acc_container),
                                max_dcc=random.choice(self.dcc_container),
                                length=length)
         else:
             print('\tWarning: cannot generate train: confliting routing. \
                 Hold new train for routing availablity.')
     else:
         print('\tWarning: cannot generate train: Capacity Maxed-out. \
             Hold new train for capacity.')
     return _new_train
Exemplo n.º 18
0
def evaluate_hardcore_wrapper(args):
    train_cls = Train(path=conf["path_data"],
                      seed=conf["seed"],
                      custom=conf["custom"],
                      validation_portion=conf["val_portion"],
                      test_portion=conf["test_portion"],
                      hardcore_path=conf["hardcore_path"])
    train_cls.evaluate(conf["path_model"])
Exemplo n.º 19
0
def evaluate_wrapper(args):
    train_cls = Train(path=conf["path_data"],
                      seed=conf["seed"],
                      custom=conf["custom"],
                      validation_portion=conf["val_portion"],
                      test_portion=conf["test_portion"])
    train_cls.evaluate(path_model=conf['path_model'],
                       batch_size=conf['eval_batch_size'])
Exemplo n.º 20
0
def start_train(train_iter, dev_iter, test_iter, model, config):
    t = Train(train_iter=train_iter,
              dev_iter=dev_iter,
              test_iter=test_iter,
              model=model,
              config=config)
    t.train()
    config.logger.info("Finish Train.")
    return t
Exemplo n.º 21
0
Arquivo: pull.py Projeto: zhasulan/mab
def main(actions, experiments, pulls):
    train = Train(experiments, pulls, actions)
    train.run("Greedy", "greedy")
    train.run("Epsilon greedy with epsilon=0.1", "epsilon_greedy", epsilon=0.1)
    train.run("Epsilon greedy with epsilon=0.01",
              "epsilon_greedy",
              epsilon=0.01)

    train.show()
Exemplo n.º 22
0
 def Train8():
     modelO = ModelThreeDensesReluSigmoidMasked(midDim1=256,
                                                midDim2=256,
                                                loss='mean_squared_error')
     modelX = ModelThreeDensesReluSigmoidMasked(midDim1=256,
                                                midDim2=256,
                                                loss='mean_squared_error')
     trainer = Train(modelO, modelX, batch=32)
     trainer.Train(1000, "O8.h5", "X8.h5",
                   "info8-midDim1=256-midDim2=256.json")
Exemplo n.º 23
0
 def Train9():
     modelO = ModelThreeDensesReluReluAdamMasked(midDim1=256,
                                                 midDim2=256,
                                                 loss='mean_squared_error')
     modelX = ModelThreeDensesReluReluAdamMasked(midDim1=256,
                                                 midDim2=256,
                                                 loss='mean_squared_error')
     trainer = Train(modelO, modelX, batch=32)
     trainer.Train(2000, "O9.h5", "X9.h5",
                   "info9-midDim1=256-midDim2=256-relu-adam.json")
Exemplo n.º 24
0
    def __init__(self, task_queue, result_queue, x, y, folds, solver, scorer):
        multiprocessing.Process.__init__(self)
        Train.__init__(self, x=x, y=y, solver=solver, scorer=scorer, number_of_folds=len(folds))

        # queues for inter-process communication
        self.task_queue = task_queue
        self.result_queue = result_queue

        # store folds
        self.folds = folds
Exemplo n.º 25
0
def main():
    parser = argparse.ArgumentParser(description='cifar-10 with pytorch')
    parser.add_argument('--lr', default=0.001, type=float)
    parser.add_argument('--epoch', default=200, type=int)
    parser.add_argument('--train_batch_size', default=100, type=int)
    parser.add_argument('--test_batch_size', default=100, type=int)
    args = parser.parse_args()

    train_net = Train(args)
    train_net.run()
Exemplo n.º 26
0
def model_parameters():
    from train import Train
    model = Train().model

    print('========== Begin someting about model parameters:')
    print("Encoder Model Parameters:", sum(p.nelement() for p in model.encoder.parameters()))
    print("Decoder Model Parameters:", sum(p.nelement() for p in model.decoder.parameters()))
    print("Reduce State Model Parameters:", sum(p.nelement() for p in model.reduce_state.parameters()))
    print("Total Model Parameters:", sum(p.nelement() for p in model.parameters()))
    print()
Exemplo n.º 27
0
def playGame(observe=False):
    tensorModel = buildModel()
    game = Game()
    agent = Agent(game)
    train = Train(agent, game)

    try:
        train.trainNetwork(tensorModel, observe=observe)
    except StopIteration:
        game.End()
Exemplo n.º 28
0
def train_wrapper(args):
    train_cls = Train(path=conf["path_data"],
                      seed=conf["seed"],
                      custom=conf["custom"],
                      validation_portion=conf["val_portion"],
                      test_portion=conf["test_portion"])
    train_cls.train(path_params=conf["path_params"],
                    path_model=conf["path_model"],
                    plot_chart=conf["plot_chart"],
                    handmade_params=conf["handmade_params"])
Exemplo n.º 29
0
def main(argv):
    if argv[1] == 'train_process':
        get_data()
        data_preparation = DataPreparation()
        data_preparation.generate_data_for_model()
        train_model = Train()
        train_model.compute_locations_models()
        prediction = Prediction()
        prediction.get_models()
        create_dashboard(prediction)
Exemplo n.º 30
0
    def simulate(self, tick):
        """
        This function will simulate the schedules for the given tick. It will make sure that the correct train is spawned at the correct station
        at exactly the time it should depart. It will also add itself to that train, so the train knows which stations to visit.

        Parameters:
            - tick: the current simulation tick, used for timing
        """
        if self.get_minutes(tick) == self.times[
                0].departure and self.get_seconds_remaining(
                    tick) < self._interval:
            t = Train()
            t.add_schedule(self.times, tick)
            self.trains.append(t)
            self.times[0].station.add_train(t)

        for t in self.trains:
            t.simulate(tick)

            # when the train is terminated, add all its delays and arrivals to the
            # total amount of the current traject
            if t.is_terminated():
                self.on_time += t.on_time
                self.delayed += t.delayed

                t.on_time = 0
                t.delayed = 0
Exemplo n.º 31
0
    def __init__(self, x, y, solver=LeastSquares, scorer=MeanAbsolute, number_of_folds=5):
        Train.__init__(self, x=x, y=utilities.to_column_matrix(y), solver=solver(), scorer=scorer(),
                       number_of_folds=number_of_folds)

        # post-training data
        self.column_indices = None
        self.fit = None
        self.score = None

        # configuration
        self.debug = 0
Exemplo n.º 32
0
    def __init__(self, x, y, solver=LeastSquares, scorer=MeanAbsolute, number_of_folds=5):
        Train.__init__(self, x=x, y=utilities.to_column_matrix(y), solver=solver(), scorer=scorer(),
                       number_of_folds=number_of_folds)

        # post-training data
        self.column_indices = None
        self.fit = None
        self.score = None

        # configuration
        self.debug = 0
def main(argv):
    parser = get_parser()
    (options, args) = parser.parse_args(argv)
    if not (options.input and options.output):
        parser.error("Requires arguments not provided")
    else:
        lang = detect_language(options.input)
        if lang not in ['en', 'es', 'it', 'nl']:
            print >> sys.stderr, 'Language other than en, es, it, nl'
            sys.exit(1)
        else:


            training_data = TrainingData(path=options.input).load_data()  # load training data
            #age gender
            configure_obj_ag = configure_age_gender(lang)  # apply which features to use
            label_encoder_ag = preprocessing.LabelEncoder()  # map feature name to integer index

            log_reg = linear_model.LogisticRegression(dual=True, multi_class='multinomial',
                                                      solver='lbfgs')  # multiclass classifier
            model_age_gender = Train(configuration=configure_obj_ag,
                          classifier=log_reg)  # create train pipeline


            #personality
            configure_obj_per=configure_personality(lang)

            label_encoder_per = preprocessing.MultiLabelBinarizer()
            # label_encoder_per = None

            linear_reg=OneVsRestClassifier(linear_model.LogisticRegression(dual=True))

            model_per = Train(configuration=configure_obj_per,
                          classifier=linear_reg)


            print "Training ......."

            model_age_gender.train(training_data.X,training_data.transform_label(label_extractor_age_gender,label_encoder_ag))
            model_per.train(training_data.X,training_data.transform_label(label_extractor_personality,label_encoder_per))

            print "Done "
            print "Saving model in {0} ".format(options.output)

            if not os.path.exists(os.path.join(options.output, lang)):
                os.mkdir(os.path.join(options.output, lang))

            model_age_gender.save(os.path.join(options.output, lang, 'age_gender.model'))
            model_per.save(os.path.join(options.output, lang, 'personality.model'))

            save_label_encoder(label_encoder_ag,options.output,lang,'age_gender.le')
            save_label_encoder(label_encoder_per,options.output,lang,'personality.le')

            print "Done saving model"
Exemplo n.º 34
0
	def retrieveSourcePage(self, trainId, theDate):
		from train import Train
		query = Train.query(Train.trainId == trainId,
				Train.date == theDate)
		tmp = query.get()
		if tmp:
			return tmp.timings
		return ""
Exemplo n.º 35
0
def main():
    # Parse the JSON arguments
    config_args = parse_args()

    # Create the experiment directories
    _, config_args.summary_dir, config_args.checkpoint_dir = create_experiment_dirs(config_args.experiment_dir)

    # Reset the default Tensorflow graph
    tf.reset_default_graph()

    # Tensorflow specific configuration
    config = tf.ConfigProto(allow_soft_placement=True)
    config.gpu_options.allow_growth = True
    sess = tf.Session(config=config)

    # Data loading
    # The batch size is equal to 1 when testing to simulate the real experiment.
    data_batch_size = config_args.batch_size if config_args.train_or_test == "train" else 1
    data = DataLoader(data_batch_size, config_args.shuffle)
    print("Loading Data...")
    config_args.img_height, config_args.img_width, config_args.num_channels, \
    config_args.train_data_size, config_args.test_data_size = data.load_data()
    print("Data loaded\n\n")

    # Model creation
    print("Building the model...")
    model = ShuffleNet(config_args)
    print("Model is built successfully\n\n")

    # Parameters visualization
    show_parameters()

    # Summarizer creation
    summarizer = Summarizer(sess, config_args.summary_dir)
    # Train class
    trainer = Train(sess, model, data, summarizer)

    if config_args.train_or_test == 'train':
        try:
            # print("FLOPs for batch size = " + str(config_args.batch_size) + "\n")
            # calculate_flops()
            print("Training...")
            trainer.train()
            print("Training Finished\n\n")
        except KeyboardInterrupt:
            trainer.save_model()

    elif config_args.train_or_test == 'test':
        # print("FLOPs for single inference \n")
        # calculate_flops()
        # This can be 'val' or 'test' or even 'train' according to the needs.
        print("Testing...")
        trainer.test('val')
        print("Testing Finished\n\n")

    else:
        raise ValueError("Train or Test options only are allowed")
Exemplo n.º 36
0
def main():
    ### Train Wenjun's classifier
    # Name of files needed when training a model
    date = time.strftime('%Y-%m-%d')
    train_file = 'training' # name of original training file
    feature_file = 'models/training_file_'+date # name of transformed training file
    feature_output = 'models/features_'+date # name of feature file
    stpfile = 'english.stp' # english stopwords file
    feature_arg = '-uni -pos2 -stem -stprm' # types of features need to extract

    log = open('models/training_log','a') # log file
    log.write('Feature Arguments: %s\n-------------------------------\n'% feature_arg)

    # Create appropriate input file for LibLINEAR (SVM)
    training = Train(train_file, stpfile, feature_output, feature_file, feature_arg)
    training.convert_file()
    # Use LibLINEAR to train the model and save the model
    y, x = svm_read_problem(feature_file)
    m = train(y, x, '-c 3 -s 1 -B 1 -e 0.01 -v 5 -q')
    save_model('models/model_'+date, m)
    """
Exemplo n.º 37
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/10/2
# @Author : JRP - Ruipeng Jia

from config import args
from preview import preview_args
from train import Train


if __name__ == '__main__':
    preview_args(args)
    train_processor = Train()
    train_processor.test()


Exemplo n.º 38
0
# train.new_network(params, layers)
# train.train_network()


## load data
load = LoadData()
training_data, validation_data, test_data = load.load_data_shared()
mini_batch_size = 10

data = [("Training data", training_data), ("Validation data", validation_data), ("Test data", test_data)]

para = "/Users/ducprogram/Dropbox/Programming/Convnet/2015-09-04 09-14-06 - Parameters.csv"
archi = "/Users/ducprogram/Dropbox/Programming/Convnet/2015-09-04 09-14-06 - Architecture.txt"
wb = "/Users/ducprogram/Dropbox/Programming/Convnet/2015-09-04 09-14-06 - WBs.zip"

train = Train(new=False)
train.load_network(para, archi, wb, data)
train.train_network()


# printed = [("ConvolutionalLayer", [("filter_shape", (20, 1, 5, 5)),
# 								   ("image_shape", (mini_batch_size, 1, 28, 28))]),
# 		   ("Subsampling", [("last_conv_shape", (20, 1, 5, 5))]),
# 		   ("ConvolutionalLayer", [("filter_shape", (40, 20, 5, 5)),
# 								   ("image_shape", (mini_batch_size, 20, 12, 12))]),
# 		   ("Subsampling", [("last_conv_shape", (40, 20, 5, 5))]),
# 		   ("FullyConnectedLayer", [("n_in", 40*4*4),
# 		   							("n_out", 1000),
# 		   							("p_dropout", 0.5)]),
# 		   ("FullyConnectedLayer", [("n_in", 1000),
# 		   							("n_out", 1000),
Exemplo n.º 39
0
    # Initialize the game object with the chosen game.
    game = object
    if CFG.game == 0:
        game = TicTacToeGame()
    elif CFG.game == 1:
        game = OthelloGame()
    elif CFG.game == 2:
        game = ConnectFourGame()
    elif CFG.game == 3:
        game = RubiksCubeGame()

    net = NeuralNetworkWrapper(game)

    # Initialize the network with the best model.
    if CFG.load_model:
        file_path = CFG.model_directory + "best_model.meta"
        if os.path.exists(file_path):
            net.load_model("best_model")
        else:
            print("Trained model doesn't exist. Starting from scratch.")
    else:
        print("Trained model not loaded. Starting from scratch.")

    # Play vs the AI as a human instead of training.
    if CFG.human_play:
        human_play = HumanPlay(game, net)
        human_play.play()
    else:
        train = Train(game, net)
        train.start()