Exemplo n.º 1
0
    def run(self):
        model = Model()
        model.train()
         
        # pickled binary file 형태로 저장된 객체를 로딩한다 
        file_name = '/home/pi/workspace/ai-contents-maze-runner/model/rf.pkl' 
        rfmodel = joblib.load(file_name) 
        
        while True:
            time.sleep(0.01)
            ir1 = self.ir1.proximity
            ir2 = self.ir2.proximity
            if ir2 == 0:
                pass
            else:
                pred = rfmodel.predict([[ir1, ir2, ir1-ir2, ir1/ir2]])
                print("예측값 : ",pred)

                if pred[0] == 1:
                    self.left_fast()
                elif pred[0] == 2:
                    self.left_slow()
                elif pred[0] == 3:
                    self.straight()
                elif pred[0] == 4:
                    self.right_slow()
                elif pred[0] == 5:
                    self.right_fast()
Exemplo n.º 2
0
def resume(model_path):
    model = Model()
    if model_path:
        model.load_state(model_path)

    for i in range(n_epochs):
        model.train()

        if model.epoch % eval_per_epoch == 0:
            model.eval()
Exemplo n.º 3
0
def main(_):

    tfconfig = tf.compat.v1.ConfigProto(allow_soft_placement=False)
    tfconfig.gpu_options.allow_growth = True
    with tf.compat.v1.Session(config=tfconfig) as sess:
        model = Model(sess, args)

        if args.phase == 'train':
            print('Train')
            model.train(args)

        if args.phase == 'inference' or args.phase == 'test':
            print("Inference.")
            model.inference(args.inference_images_dir,
                            to_save_dir=args.save_dir)
        sess.close()
    print('FINISHED')
 def train(self):
     model = Model()
     model.train()
Exemplo n.º 5
0
        model2 = load_model('models/model_{}.h5'.format(current_generation -
                                                        1))
        agent1 = Agent(model1, probabilistic_prediction=0.3).agent
        agent2 = Agent(model2, probabilistic_prediction=0.3).agent
    except:
        model1 = None
        model2 = None
        agent1 = None
        agent2 = None
    # Play
    print('Playing generation {} vs {}...'.format(current_generation,
                                                  current_generation - 1))
    simulation = Simulation(loops=100,
                            agents=[agent1, agent2],
                            exploration=0.2)
    simulation.start()
    winner_moves = simulation.get_winner_moves()
    print('Game finished. We collected {} winner moves!'.format(
        len(winner_moves)))
    # Train
    print('Training new generation...')
    new_model = Model(pretrained_model=model1)
    new_trained_model = new_model.train(moves=winner_moves, epochs=100)
    new_model.save('models/model_{}.h5'.format(current_generation + 1))
    # Write metadata
    print('Training finished. Writing metadata...')
    metadata['latest_generation_trained'] = current_generation + 1
    with open('metadata.json', 'w') as f:
        f.write(json.dumps(metadata, indent=2))
    current_generation += 1
Exemplo n.º 6
0
from train import Model
import sys

data_name = sys.argv[1]
model = Model(data_name)
model.train()
Exemplo n.º 7
0
            config.learning_rate = 0.001
            config.training_epoch = 200
        elif config.model_type == "simplE":
            config.batchSize = 100
            # config.weight_decay = 0.001
            config.embedding_dim = 200
            config.learning_rate = 0.001
            config.training_epoch = 30
        elif config.model_type == "convE":
            config.batchSize = 128
            config.learning_rate = 0.001
            config.embedding_dim = 200
            config.training_epoch = 100
        elif config.model_type == "transE":
            config.batchSize = 256
            config.embedding_dim = 100
            config.learning_rate = 0.001
            config.margin = 1
            config.training_epoch = 100
        elif config.model_type == "rotatE":
            config.batchSize = 256
            config.gamma = 3.0
            config.adversial_alpha = 0.5
            config.embedding_dim = 250
            config.learning_rate = 0.001
            config.training_epoch = 100


    md = Model(config)
    md.train(50, 0.2)
Exemplo n.º 8
0
                         for items in content))  #content是要保存的list。
        fobj.close()
        print(content)
        mkdir(mkpath)
        CatchPICFromVideo("Video", 0, 200, mkpath)
    #read
    images, labels = load_dataset('data')
    #train
    dataset = Dataset('data')
    dataset.load()

    model = Model()
    model.build_model(dataset)

    #测试训练函数的代码
    model.train(dataset)
    #print("197 ok")
    model.save_model(file_path='./model/me.face.model.h5')
    model = Model()
    model.load_model(file_path='./model/me.face.model.h5')
    model.evaluate(dataset)
    #predict
    file_object = open('content.txt')
    name = file_object.read().split('\n')
    for i in name:
        if i == '':
            name.remove('')
    model = Model()
    model.load_model(file_path='./model/me.face.model.h5')

    #框住人脸的矩形边框颜色
Exemplo n.º 9
0
    (512, 4, 0.5, 0)  # [batch, 2, 2, 512] => [batch, 1, 1, 512]
]

kernels_gen_decoder = [
    # out_channel, kernel_size, keep_drop, norm_or_not
    (512, 4, 0.5, 1),  # [batch, 1, 1, 512] => [batch, 2, 2, 512+512]
    (512, 4, 0.5, 1),  # [batch, 2, 2, 1024] => [batch, 4, 4, 512+512]
    (512, 4, 0.5, 1),  # [batch, 4, 4, 1024] => [batch, 8, 8, 512+512]
    (512, 4, 0.5, 1),  # [batch, 8, 8, 1024] => [batch, 16, 16, 512+512]
    (256, 4, 1.0, 1),  # [batch, 16, 16, 1024] => [batch, 32, 32, 256+256]
    (128, 4, 1.0, 1),  # [batch, 32, 32, 512] => [batch, 64, 64, 128+128]
    (64, 4, 1.0, 1)  # [batch, 64, 64, 256] => [batch, 128, 128, 64+64]
]

kernels_dis = [
    # out_channel, kernel_size
    (64, 4),  # [batch, 256, 256, ch] => [batch, 128, 128, 64]
    (128, 4),  # [batch, 128, 128, 64] => [batch, 64, 64, 128]
    (256, 4),  # [batch, 64, 64, 128] => [batch, 32, 32, 256]
    (512, 4)  # [batch, 32, 32, 256] => [batch, 16, 16, 512]
]

with tf.device('gpu:1'):
    pix2pix = Model(kernels_gen_encoder,
                    kernels_gen_decoder,
                    kernels_dis,
                    trainning=True)
    pix2pix.build(lambda_pixel=100.0)
    pix2pix.net_initial()
    pix2pix.train(epochs=201)
Exemplo n.º 10
0
from train import Model
import pickle, json
import pandas as pd

if __name__ == '__main__':
    with open('traindata.json', 'r') as fp:
        data = json.load(fp)

    X_train = pd.Series(json.loads(data['X_train']))
    y_train = pd.Series(json.loads(data['y_train']))

    m = Model(X_train, y_train)
    cv, cv_train_reviews = m.train()
    print(cv)
    lr = m.model(cv_train_reviews)
    print(lr)
    with open('model.pkl', 'wb') as fout:
        pickle.dump((cv, lr), fout)