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


Python model.Model方法代码示例

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


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

示例1: main

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def main(cache_dir):
    files_list = list(os.listdir(cache_dir))
    for file in files_list:
        full_filename = os.path.join(cache_dir, file)
        if os.path.isfile(full_filename):
            print("Processing {}".format(full_filename))
            m, stored_kwargs = pickle.load(open(full_filename, 'rb'))
            updated_kwargs = util.get_compatible_kwargs(model.Model, stored_kwargs)

            model_hash = util.object_hash(updated_kwargs)
            print("New hash -> " + model_hash)
            model_filename = os.path.join(cache_dir, "model_{}.p".format(model_hash))
            sys.setrecursionlimit(100000)
            pickle.dump((m,updated_kwargs), open(model_filename,'wb'), protocol=pickle.HIGHEST_PROTOCOL)

            os.remove(full_filename) 
开发者ID:hexahedria,项目名称:gated-graph-transformer-network,代码行数:18,代码来源:update_cache_compatibility.py

示例2: _eval

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def _eval(path_to_checkpoint: str, dataset_name: str, backbone_name: str, path_to_data_dir: str, path_to_results_dir: str):
    dataset = DatasetBase.from_name(dataset_name)(path_to_data_dir, DatasetBase.Mode.EVAL, Config.IMAGE_MIN_SIDE, Config.IMAGE_MAX_SIDE)
    evaluator = Evaluator(dataset, path_to_data_dir, path_to_results_dir)

    Log.i('Found {:d} samples'.format(len(dataset)))

    backbone = BackboneBase.from_name(backbone_name)(pretrained=False)
    model = Model(backbone, dataset.num_classes(), pooler_mode=Config.POOLER_MODE,
                  anchor_ratios=Config.ANCHOR_RATIOS, anchor_sizes=Config.ANCHOR_SIZES,
                  rpn_pre_nms_top_n=Config.RPN_PRE_NMS_TOP_N, rpn_post_nms_top_n=Config.RPN_POST_NMS_TOP_N).cuda()
    model.load(path_to_checkpoint)

    Log.i('Start evaluating with 1 GPU (1 batch per GPU)')
    mean_ap, detail = evaluator.evaluate(model)
    Log.i('Done')

    Log.i('mean AP = {:.4f}'.format(mean_ap))
    Log.i('\n' + detail) 
开发者ID:potterhsu,项目名称:easy-faster-rcnn.pytorch,代码行数:20,代码来源:eval.py

示例3: main

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def main():
    parser = argparse.ArgumentParser(description='test', formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument(
        '-a', '--attributes',
        nargs='+',
        type=str,
        help='Specify attribute name for training. \nAll attributes can be found in list_attr_celeba.txt'
    )
    parser.add_argument(
        '-g', '--gpu',
        default='0',
        type=str,
        help='Specify GPU id. \ndefault: %(default)s. \nUse comma to seperate several ids, for example: 0,1'
    )
    args = parser.parse_args()

    celebA = Dataset(args.attributes)
    DNA_GAN = Model(args.attributes, is_train=True)
    run(config, celebA, DNA_GAN, gpu=args.gpu) 
开发者ID:Prinsphield,项目名称:DNA-GAN,代码行数:21,代码来源:train.py

示例4: _eval

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def _eval(path_to_checkpoint, backbone_name, path_to_results_dir):
    dataset = AVA_video(EvalConfig.VAL_DATA)
    evaluator = Evaluator(dataset, path_to_results_dir)

    Log.i('Found {:d} samples'.format(len(dataset)))

    backbone = BackboneBase.from_name(backbone_name)()
    model = Model(backbone, dataset.num_classes(), pooler_mode=Config.POOLER_MODE,
                  anchor_ratios=Config.ANCHOR_RATIOS, anchor_sizes=Config.ANCHOR_SIZES,
                  rpn_pre_nms_top_n=TrainConfig.RPN_PRE_NMS_TOP_N, rpn_post_nms_top_n=TrainConfig.RPN_POST_NMS_TOP_N).cuda()
    model.load(path_to_checkpoint)
    print("load from:",path_to_checkpoint)
    Log.i('Start evaluating with 1 GPU (1 batch per GPU)')
    mean_ap, detail = evaluator.evaluate(model)
    Log.i('Done')
    Log.i('mean AP = {:.4f}'.format(mean_ap))
    Log.i('\n' + detail) 
开发者ID:MagicChuyi,项目名称:SlowFast-Network-pytorch,代码行数:19,代码来源:eval.py

示例5: sample

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def sample(args):
    with open(os.path.join(args.save_dir, 'config.pkl'), 'rb') as f:
        saved_args = cPickle.load(f)
    with open(os.path.join(args.save_dir, 'chars_vocab.pkl'), 'rb') as f:
        chars, vocab = cPickle.load(f)
    #Use most frequent char if no prime is given
    if args.prime == '':
        args.prime = chars[0]
    model = Model(saved_args, training=False)
    with tf.Session() as sess:
        tf.global_variables_initializer().run()
        saver = tf.train.Saver(tf.global_variables())
        ckpt = tf.train.get_checkpoint_state(args.save_dir)
        if ckpt and ckpt.model_checkpoint_path:
            saver.restore(sess, ckpt.model_checkpoint_path)
            data = model.sample(sess, chars, vocab, args.n, args.prime,
                               args.sample).encode('utf-8')
            print(data.decode("utf-8")) 
开发者ID:sherjilozair,项目名称:char-rnn-tensorflow,代码行数:20,代码来源:sample.py

示例6: main

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def main(_):
    dataset = get_record_dataset(FLAGS.record_path)
    data_provider = slim.dataset_data_provider.DatasetDataProvider(dataset)
    image, label = data_provider.get(['image', 'label'])
    inputs, labels = tf.train.batch([image, label],
                                    batch_size=64,
                                    allow_smaller_final_batch=True)
    
    cls_model = model.Model(is_training=True)
    preprocessed_inputs = cls_model.preprocess(inputs)
    prediction_dict = cls_model.predict(preprocessed_inputs)
    loss_dict = cls_model.loss(prediction_dict, labels)
    loss = loss_dict['loss']
    postprocessed_dict = cls_model.postprocess(prediction_dict)
    acc = cls_model.accuracy(postprocessed_dict, labels)
    tf.summary.scalar('loss', loss)
    tf.summary.scalar('accuracy', acc)
    
    optimizer = tf.train.MomentumOptimizer(learning_rate=0.01, momentum=0.9)
    train_op = slim.learning.create_train_op(loss, optimizer,
                                             summarize_gradients=True)
    
    slim.learning.train(train_op=train_op, logdir=FLAGS.logdir,
                        save_summaries_secs=20, save_interval_secs=120) 
开发者ID:Shirhe-Lyh,项目名称:multi_task_test,代码行数:26,代码来源:train.py

示例7: inference

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def inference(ckpt, inference_input_file, inference_output_file, hparams, num_workers=1, jobid=0, scope=None, single_cell_fn=None):

    """Perform translation."""
    if hparams.inference_indices:
        assert num_workers == 1

    if not hparams.attention:
        model_creator = nmt_model.Model
    elif hparams.attention_architecture == "standard":
        model_creator = attention_model.AttentionModel
    elif hparams.attention_architecture in ["gnmt", "gnmt_v2"]:
        model_creator = gnmt_model.GNMTModel
    else:
        raise ValueError("Unknown model architecture")
    infer_model = create_infer_model(model_creator, hparams, scope, single_cell_fn)

    if num_workers == 1:
        single_worker_inference(infer_model, ckpt, inference_input_file, inference_output_file, hparams)
    else:
        multi_worker_inference(infer_model, ckpt, inference_input_file, inference_output_file, hparams, num_workers=num_workers, jobid=jobid) 
开发者ID:neccam,项目名称:nslt,代码行数:22,代码来源:inference.py

示例8: main

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def main(_):
    # Specify which gpu to be used
    os.environ["CUDA_VISIBLE_DEVICES"] = '1'
    
    cls_model = model.Model(is_training=False, num_classes=61)
    if FLAGS.input_shape:
        input_shape = [
            int(dim) if dim != -1 else None 
            for dim in FLAGS.input_shape.split(',')
        ]
    else:
        input_shape = [None, None, None, 3]
    exporter.export_inference_graph(FLAGS.input_type,
                                    cls_model,
                                    FLAGS.trained_checkpoint_prefix,
                                    FLAGS.output_directory,
                                    input_shape) 
开发者ID:Shirhe-Lyh,项目名称:finetune_classification,代码行数:19,代码来源:export_inference_graph.py

示例9: main

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def main(_):
    
    with tf.device(FLAGS.device):
	
	model_save_path = 'model/'+FLAGS.model_save_path	
	# create directory if it does not exist
	if not tf.gfile.Exists(model_save_path):
		tf.gfile.MakeDirs(model_save_path)
	log_dir = 'logs/'+ model_save_path
	
	model = Model(learning_rate=0.0003, mode=FLAGS.mode)
	solver = Solver(model, model_save_path=model_save_path, log_dir=log_dir)
	
	# create directory if it does not exist
	if not tf.gfile.Exists(model_save_path):
		tf.gfile.MakeDirs(model_save_path)
	
	if FLAGS.mode == 'train':
		solver.train()
	elif FLAGS.mode == 'test':
		solver.test(checkpoint=FLAGS.checkpoint)
	else:
	    print 'Unrecognized mode.' 
开发者ID:pmorerio,项目名称:dl-uncertainty,代码行数:25,代码来源:main.py

示例10: setup_train

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def setup_train(self, model_file_path=None):
        self.model = Model(model_file_path)

        params = list(self.model.encoder.parameters()) + list(self.model.decoder.parameters()) + \
                 list(self.model.reduce_state.parameters())
        initial_lr = config.lr_coverage if config.is_coverage else config.lr
        if config.mode == 'MLE':
            self.optimizer = Adagrad(params, lr=0.15, initial_accumulator_value=0.1)
        else:
            self.optimizer = Adam(params, lr=initial_lr)

        start_iter, start_loss = 0, 0

        if model_file_path is not None:
            state = torch.load(model_file_path, map_location= lambda storage, location: storage)
            start_iter = state['iter']
            start_loss = state['current_loss']
        return start_iter, start_loss 
开发者ID:wyu-du,项目名称:Reinforce-Paraphrase-Generation,代码行数:20,代码来源:train.py

示例11: train

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def train():
    model.train()
    total_loss = 0
    for word, char, label in tqdm(training_data, mininterval=1,
                                  desc='Train Processing', leave=False):

        optimizer.zero_grad()
        loss, _ = model(word, char, label)
        loss.backward()

        optimizer.step()
        optimizer.update_learning_rate()
        total_loss += loss.data
    return total_loss / training_data._stop_step


# ##############################################################################
# Save Model
# ############################################################################## 
开发者ID:ne7ermore,项目名称:torch-light,代码行数:21,代码来源:train.py

示例12: create_model

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def create_model(self):
    return model.Model(
        self.num_char_classes, self.seq_length, num_views=4, null_code=62) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:5,代码来源:model_test.py

示例13: create_model

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def create_model(*args, **kwargs):
  ocr_model = model.Model(mparams=create_mparams(), *args, **kwargs)
  return ocr_model 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:5,代码来源:common_flags.py

示例14: get_model

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def get_model(self):
    # vocab size is the number of distinct values that
    # could go into the memory key-value storage
    vocab_size = self.episode_width * self.batch_size
    return model.Model(
        self.input_dim, self.output_dim, self.rep_dim, self.memory_size,
        vocab_size, use_lsh=self.use_lsh) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:9,代码来源:train.py

示例15: get_model

# 需要导入模块: import model [as 别名]
# 或者: from model import Model [as 别名]
def get_model(self):
    cls = model.Model
    return cls(self.env_spec, self.global_step,
               target_network_lag=self.target_network_lag,
               sample_from=self.sample_from,
               get_policy=self.get_policy,
               get_baseline=self.get_baseline,
               get_objective=self.get_objective,
               get_trust_region_p_opt=self.get_trust_region_p_opt,
               get_value_opt=self.get_value_opt) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:12,代码来源:trainer.py


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