当前位置: 首页>>代码示例>>Python>>正文


Python Model.predict方法代码示例

本文整理汇总了Python中model.Model.predict方法的典型用法代码示例。如果您正苦于以下问题:Python Model.predict方法的具体用法?Python Model.predict怎么用?Python Model.predict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.Model的用法示例。


在下文中一共展示了Model.predict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: image_train

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import predict [as 别名]
def image_train(x_train, y_train, x_test, model_path="model.json", weight_path="weights.h5"):
    netModel = Model().image_model()
    #sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
    #netModel.compile(loss='mean_squared_error', optimizer=sgd, metrics=["accuracy"])

    netModel.compile(loss='mean_squared_error', optimizer="rmsprop", metrics=["accuracy"])

    print "STARTING TRAINING"
    netModel.fit(x_train, y_train, nb_epoch=1, batch_size=10, shuffle=True, verbose=1)
    # model.fit(data, label, batch_size=100,nb_epoch=10,shuffle=True,verbose=1,show_accuracy=True,validation_split=0.2)
    y_predict = netModel.predict(x_test, batch_size=10)
    save_model(netModel, model_path, weight_path)
    return y_predict
开发者ID:hellodmp,项目名称:ImageQC_keras,代码行数:15,代码来源:test.py

示例2: Model

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import predict [as 别名]
from game import Game
from settings import settings
import numpy as np
import cv2

import lasagne

model = Model(settings)

with np.load('model.npz') as f:
    params = [f['arr_%d' % i] for i in xrange(len(f.files))]
lasagne.layers.set_all_param_values(model.q_network, params)
model.update_target_network()

cv2.startWindowThread()
cv2.namedWindow("preview")

while True:
    game = Game()
    observations = np.dstack((game.observe(),) * settings['phi_length'])[0]
    for step in xrange(settings['max_steps']):
        predictions = model.predict(observations)
        print predictions
        action = model.act(observations, settings['test_epsilon'])
        reward = game.act(action)
        observation = game.observe()
        terminal = step == settings['max_steps'] - 1

        game.draw()
        observations = np.hstack((np.expand_dims(observation, 2), observations[:,1:]))
开发者ID:amharc,项目名称:jnp3,代码行数:32,代码来源:test.py

示例3: main

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import predict [as 别名]
def main(args):
    if args.gpu >= 0:
        cuda.check_cuda_available()
    xp = cuda.cupy if args.gpu >= 0 else np

    model_id = build_model_id(args)
    model_path = build_model_path(args, model_id)
    setup_model_dir(args, model_path)
    sys.stdout, sys.stderr = setup_logging(args)

    x_train, y_train = load_model_data(args.train_file,
            args.data_name, args.target_name,
            n=args.n_train)
    x_validation, y_validation = load_model_data(
            args.validation_file,
            args.data_name, args.target_name,
            n=args.n_validation)

    rng = np.random.RandomState(args.seed)

    N = len(x_train)
    N_validation = len(x_validation)

    n_classes = max(np.unique(y_train)) + 1
    json_cfg = load_model_json(args, x_train, n_classes)

    print('args.model_dir', args.model_dir)
    sys.path.append(args.model_dir)
    from model import Model
    model_cfg = ModelConfig(**json_cfg)
    model = Model(model_cfg)
    setattr(model, 'stop_training', False)
    
    if args.gpu >= 0:
        cuda.get_device(args.gpu).use()
        model.to_gpu()
    
    best_accuracy = 0.
    best_epoch = 0
    
    def keep_training(epoch, best_epoch):
        if model_cfg.n_epochs is not None and epoch > model_cfg.n_epochs:
                return False
        if epoch > 1 and epoch - best_epoch > model_cfg.patience:
            return False
        return True
    
    epoch = 1
    
    while True:
        if not keep_training(epoch, best_epoch):
            break
    
        if args.shuffle:
            perm = np.random.permutation(N)
        else:
            perm = np.arange(N)
    
        sum_accuracy = 0
        sum_loss = 0

        pbar = progressbar.ProgressBar(term_width=40,
            widgets=[' ', progressbar.Percentage(),
            ' ', progressbar.ETA()],
            maxval=N).start()

        for j, i in enumerate(six.moves.range(0, N, model_cfg.batch_size)):
            pbar.update(j+1)
            x_batch = xp.asarray(x_train[perm[i:i + model_cfg.batch_size]].flatten())
            y_batch = xp.asarray(y_train[perm[i:i + model_cfg.batch_size]])
            pred, loss, acc = model.fit(x_batch, y_batch)
            sum_loss += float(loss.data) * len(y_batch)
            sum_accuracy += float(acc.data) * len(y_batch)

        pbar.finish()
        print('train epoch={}, mean loss={}, accuracy={}'.format(
            epoch, sum_loss / N, sum_accuracy / N))
    
        # Validation set evaluation
        sum_accuracy = 0
        sum_loss = 0

        pbar = progressbar.ProgressBar(term_width=40,
            widgets=[' ', progressbar.Percentage(),
            ' ', progressbar.ETA()],
            maxval=N_validation).start()

        for i in six.moves.range(0, N_validation, model_cfg.batch_size):
            pbar.update(i+1)
            x_batch = xp.asarray(x_validation[i:i + model_cfg.batch_size].flatten())
            y_batch = xp.asarray(y_validation[i:i + model_cfg.batch_size])
            pred, loss, acc = model.predict(x_batch, target=y_batch)
            sum_loss += float(loss.data) * len(y_batch)
            sum_accuracy += float(acc.data) * len(y_batch)

        pbar.finish()
        validation_accuracy = sum_accuracy / N_validation
        validation_loss = sum_loss / N_validation
    
        if validation_accuracy > best_accuracy:
#.........这里部分代码省略.........
开发者ID:Libardo1,项目名称:modeling,代码行数:103,代码来源:train_chainer.py


注:本文中的model.Model.predict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。