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


Python Model.Model方法代码示例

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


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

示例1: main

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def main(_):
    train_data = context_of_idx

    with tf.Graph().as_default(), tf.Session(config=config_tf) as session:
        initializer = tf.random_uniform_initializer(-config.init_scale,
                                                config.init_scale)
        with tf.variable_scope("model", reuse=None, initializer=initializer):
            m = Model.Model(is_training=True, config=config)

        tf.global_variables_initializer().run()

        model_saver = tf.train.Saver(tf.global_variables())

        for i in range(config.iteration):
            print("Training Epoch: %d ..." % (i+1))
            train_perplexity = run_epoch(session, m, train_data, m.train_op)
            print("Epoch: %d Train Perplexity: %.3f" % (i + 1, train_perplexity))

            if (i+1) % config.save_freq == 0:
                print ("model saving ...")
                model_saver.save(session, config.model_path+'-%d'%(i+1))
                print ("Done!") 
开发者ID:fukuball,项目名称:Tom-Chang-Deep-Lyrics,代码行数:24,代码来源:train.py

示例2: load_model

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def load_model(self, model_path):
        if self.use_gpu is True:
            self.model = torch.load(model_path)
            if isinstance(self.model, nn.DataParallel):
                self.model = self.model.module
            self.model.update_use_gpu(self.use_gpu)
            self.model.cuda()
            self.model = nn.DataParallel(self.model)
        else:
            self.model = torch.load(model_path, map_location='cpu')
            if isinstance(self.model, nn.DataParallel):
                self.model = self.model.module
            self.model.update_use_gpu(self.use_gpu)

        logging.info("Model %s loaded!" % model_path)
        logging.info("Total trainable parameters: %d" % (get_trainable_param_num(self.model))) 
开发者ID:microsoft,项目名称:NeuronBlocks,代码行数:18,代码来源:LearningMachine.py

示例3: test_ModelArgsHashWithDefault

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def test_ModelArgsHashWithDefault():

  M = ModelArgsHashWithDefault

  cmp_class_name_eq  ( M(      3,      4 ), M(      3,      4 ) )
  cmp_class_name_neq ( M(      3,      4 ), M(      5,      6 ) )

  cmp_class_name_eq  ( M(      3, arg2=4 ), M(      3, arg2=4 ) )
  cmp_class_name_neq ( M(      3, arg2=4 ), M(      5, arg2=6 ) )

  cmp_class_name_eq  ( M( arg1=3, arg2=4 ), M( arg1=3, arg2=4 ) )
  cmp_class_name_neq ( M( arg1=3, arg2=4 ), M( arg1=5, arg2=6 ) )

  cmp_class_name_eq  ( M( arg2=4, arg1=3 ), M( arg1=3, arg2=4 ) )
  cmp_class_name_neq ( M( arg2=4, arg1=3 ), M( arg1=5, arg2=6 ) )

  cmp_class_name_eq  ( M(      3 ), M(      3 ) )
  cmp_class_name_neq ( M(      3 ), M(      5 ) )

  cmp_class_name_eq  ( M( arg1=3 ), M( arg1=3 ) )
  cmp_class_name_neq ( M( arg1=3 ), M( arg1=5 ) )

#-----------------------------------------------------------------------
# ClassNameCollision
#-----------------------------------------------------------------------
# A model's class_name is generated during elaboration based on a hash of
# the list of arguments and their values. If two models have the same
# class name, same args, and same arg values (e.g., two Mux's each with 2
# ports and 47 bits, but one is one-hot and one is not), the hashes will
# collide. In Verilog translation, collided names result in both modules
# pointing at the same module definition, so one is incorrect.
#
# This collision is prevented by adding the model's __module__ to the hash
# generation (_gen_class_name). A class's __module__ will be different
# when importing from different modules.
#
# This test case creates two models of class name ClassNameCollisionModel,
# one in this module and one in the Model_dummy_test.py module. They have
# the same name and same args. The test case checks that their Model
# class_name's do not collide after elaborate. 
开发者ID:cornell-brg,项目名称:pymtl,代码行数:42,代码来源:Model_test.py

示例4: train

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def train(dances_lst, param):
    torch.cuda.set_device(param.device)
    
    print ("####Initiate model AE")
    
    model = Model.Model(joint_num=57,out_rotation_mode=param.out_rotation_mode)
    if(param.read_weight_path!=""):
        print ("Load "+param.read_weight_path)
        model.load_state_dict(torch.load(param.read_weight_path))
    model.cuda()
    optimizer = torch.optim.Adam(model.parameters(), lr=param.lr)#, betas=(0.5,0.9))
    model.train()
    
    model.initialize_skeleton_features("../data/standard.bvh")
   
    print ("start train")
 
    for iteration in range(param.start_iteration,param.total_iteration):   
                
        save_bvh=False
        if(iteration%param.save_bvh_iteration==0):
            save_bvh=True
        train_one_iteraton(param.logger, dances_lst,  param, model, optimizer, 
                           iteration, save_bvh )

        if(iteration%param.save_weight_iteration == 0):
           
            path = param.write_weight_folder + "model_%07d"%iteration 
            #print ("save_weight:  " + path)
            torch.save(model.state_dict(), path+".weight")
            
        if(iteration%10000 == 0):
            path = param.write_weight_folder + "model"
            torch.save(model.state_dict(), path+".weight") 
开发者ID:papagina,项目名称:RotationContinuity,代码行数:36,代码来源:trainIK.py

示例5: __init__

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def __init__(self, params):
        self._epochs = params['EPOCHS']
        self._batch_size = params['BATCH_SIZE']
        self._lr = params['LEARNING_RATE']
        self._n_class = params['N_CLASS']
        self._divide_lr = params['DIVIDE_LEARNING_RATE_AT']

        self.data = Data(params)
        self.model = Model(params)

        self._save_path = os.path.abspath('./Model') 
开发者ID:Prasad9,项目名称:TFHubSample,代码行数:13,代码来源:Train.py

示例6: __init__

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def __init__(self, params):
        self._batch_size = params['BATCH_SIZE']

        self.data = Data(params)
        self.model = Model(params) 
开发者ID:Prasad9,项目名称:TFHubSample,代码行数:7,代码来源:Infer.py

示例7: __init__

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def __init__(self, params):
        self._batch_size = params['BATCH_SIZE']
        self._top_k = params['PLOT_TOP_K']
        self._save_path = os.path.abspath(params['INFER_PATH'] + 'Plot')

        self.data = Data(params)
        self.model = Model(params) 
开发者ID:Prasad9,项目名称:TFHubSample,代码行数:9,代码来源:Infer.py

示例8: __init__

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def __init__(self, params):
        self._epochs = params['EPOCHS']
        self._batch_size = params['BATCH_SIZE']
        self._lr = params['LEARNING_RATE']
        self._n_class = params['N_CLASS']

        self.data = Data(params)
        self.model = Model(params)

        self._save_path = os.path.abspath('./Model') 
开发者ID:Prasad9,项目名称:TFHubSample,代码行数:12,代码来源:Train.py

示例9: __init__

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def __init__(self, params):
        self._epochs = params['EPOCHS']
        self._batch_size = params['BATCH_SIZE']
        self._lr = params['LEARNING_RATE']
        self._divide_lr = params['DIVIDE_LEARNING_RATE_AT']

        self.data = Data(params)
        n_class = len(params['REQD_LABELS'])
        self.model = Model(params, n_class=n_class)
        self._save_path = os.path.abspath('./Model') 
开发者ID:Prasad9,项目名称:TFHubSample,代码行数:12,代码来源:Train.py

示例10: __init__

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def __init__(self, params):
        self._epochs = params['EPOCHS']
        self._batch_size = params['BATCH_SIZE']
        self._lr = params['LEARNING_RATE']
        self._n_class = params['N_CLASS']
        self._divide_lr = params['DIVIDE_LEARNING_RATE_AT']

        self.data = Data(params)
        self.model = Model(params)

        self.save_path = os.path.abspath('./Model') 
开发者ID:Prasad9,项目名称:TFHubSample,代码行数:13,代码来源:Train.py

示例11: __init__

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def __init__(self, params):
        self._setup_files(params['SRC_PATH'], params['DST_PATH'])
        self.augmentations_per_image = params['AUGMENTATIONS_PER_IMAGE']

        self.model = Model(params) 
开发者ID:Prasad9,项目名称:TFHubSample,代码行数:7,代码来源:Augment.py

示例12: createModel

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def createModel(config_path, checkpoint_path, graph_path):
    """ Create a TensorRT Model.
    config_path (string) - The path to the model config file.
    checkpoint_path (string) - The path to the model checkpoint file(s).
    graph_path (string) - The path to the model graph.
    returns (Model) - The TRT model built or loaded from the input files.
    """

    global build_graph, prev_classes

    trt_graph = None
    input_names = None
    
    if build_graph:
        frozen_graph, input_names, output_names = build_detection_graph(
            config=config_path,
            checkpoint=checkpoint_path
        )
    
        trt_graph = trt.create_inference_graph(
            input_graph_def=frozen_graph,
            outputs=output_names,
            max_batch_size=1,
            max_workspace_size_bytes=1 << 25,
            precision_mode='FP16',
            minimum_segment_size=50
        )

        with open(graph_path, 'wb') as f:
            f.write(trt_graph.SerializeToString())

        with open('config.txt', 'r+') as json_file:  
            data = json.load(json_file)
            data['model'] = []
            data['model'] = [{'input_names': input_names}]
            json_file.seek(0)
            json_file.truncate()
            json.dump(data, json_file)

    else:
        with open(graph_path, 'rb') as f:
            trt_graph = tf.GraphDef()
            trt_graph.ParseFromString(f.read())
        with open('config.txt') as json_file:  
            data = json.load(json_file)
            input_names = data['model'][0]['input_names']

    return Model(trt_graph, input_names) 
开发者ID:NVIDIA-AI-IOT,项目名称:GreenMachine,代码行数:50,代码来源:GreenMachine.py

示例13: test_ClassNameCollision

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def test_ClassNameCollision():
  model1 = ClassNameCollisionModel     ( 1, 2 ) # same arg values
  model2 = ClassNameCollisionModelDummy( 1, 2 ) # same arg values
  model1.elaborate()
  model2.elaborate()
  assert model1.class_name != model2.class_name

#-----------------------------------------------------------------------
# ClassNameCollisionSameModule
#-----------------------------------------------------------------------
# The ClassNameCollision test case checks for class name collisions due to
# same-name same-args classes in _different_ modules. Collisions can still
# happen if the same-name same-arg classes are in the same module. This
# test case checks for this kind of collision using two classes named
# "ClassNameCollision" placed at different levels of the hierarchy, but
# instantiated with the same name and same args.
#
# TODO: This corner case is not yet fixed and may not need to be fixed. If
# this seems like it is ever going to happen in practice, we will need
# this test case to pass. This test case will pass if we use __class__ in
# the class name generation (_gen_class_name). While this always avoids
# collisions, it also gives a differently named translated Verilog file on
# every run. Having the filename always changing can make it difficult for
# other tools to point to the generated Verilog. Using __module__ in the
# hash generation still avoids class name collisions across modules but
# also keeps the name of the translated Verilog file the same. It means we
# are not avoiding same-class-name same-args collisions in the same
# module, but this seems kind of rare.

# class ClassNameCollisionSameModule( Model ):
#   def __init__( s, arg1, arg2 ):
#     s.arg1 = arg1
#     s.arg2 = arg2
#
#   class ClassNameCollisionSameModule( Model ):
#     def __init__( s, arg1, arg2 ):
#       s.arg1 = arg1
#       s.arg2 = arg2
#
# def test_ClassNameCollisionSameModule():
#   model1 = ClassNameCollisionSameModule( 1, 2 )
#   model2 = ClassNameCollisionSameModule.ClassNameCollisionSameModule( 1, 2 )
#   model1.elaborate()
#   model2.elaborate()
#   assert model1.class_name != model2.class_name 
开发者ID:cornell-brg,项目名称:pymtl,代码行数:47,代码来源:Model_test.py

示例14: __init__

# 需要导入模块: import Model [as 别名]
# 或者: from Model import Model [as 别名]
def __init__(self, phase, conf, problem, vocab_info=None, initialize=True, use_gpu=False, **kwargs):
        if initialize is True:
            assert vocab_info is not None
            self.model = Model(conf, problem, vocab_info, use_gpu)
            if use_gpu is True:
                self.model = nn.DataParallel(self.model)
                self.model = transfer_to_gpu(self.model)
            # judge the embedding matrix weight's device
            emb_weight_device = list(self.model.module.layers.embedding.embeddings.values())[0].weight.device.type if isinstance(self.model, nn.DataParallel) \
                else list(self.model.layers.embedding.embeddings.values())[0].weight.device.type
            device = 'GPU' if 'cuda' in emb_weight_device else 'CPU'
            logging.info(
                "The embedding matrix is on %s now, you can modify the weight_on_gpu parameter to change embeddings weight device." % device)
            logging.info("="*100 + '\n' + "*"*15 + "Model Achitecture" + "*"*15)
            logging.info(self.model)
            #logging.info("Total parameters: %d; trainable parameters: %d" % (get_param_num(self.model), get_trainable_param_num(self.model)))
            logging.info("Total trainable parameters: %d" % (get_trainable_param_num(self.model)))
            logging.info("Model built!")
        else:
            self.model = None

        self.conf = conf
        self.problem = problem
        self.phase = phase
        self.use_gpu = use_gpu

        # if it is a 2-class classification problem, figure out the real positive label
        # CAUTION: multi-class classification
        if phase != 'predict':
            if 'auc' in conf.metrics:
                if not hasattr(self.conf, 'pos_label') or self.conf.pos_label is None:
                    if problem.output_dict.cell_num() == 2 and \
                        problem.output_dict.has_cell("0") and problem.output_dict.has_cell("1"):
                        self.conf.pos_label = problem.output_dict.id("1")
                        logging.debug("Postive label (target index): %d" % self.conf.pos_label)
                    else:
                        # default
                        raise Exception('Please configure the positive label for auc metric at inputs/positive_label in the configuration file')
                else:
                    self.conf.pos_label = problem.output_dict.id(self.conf.pos_label)
            else:
                self.conf.pos_label = 1  # whatever

            self.metrics = conf.metrics
            if ProblemTypes[self.problem.problem_type] == ProblemTypes.classification \
                or ProblemTypes[self.problem.problem_type] == ProblemTypes.sequence_tagging:
                self.evaluator = Evaluator(metrics=self.metrics, pos_label=self.conf.pos_label, tagging_scheme=problem.tagging_scheme, label_indices=self.problem.output_dict.cell_id_map)
            elif ProblemTypes[self.problem.problem_type] == ProblemTypes.regression:
                self.evaluator = Evaluator(metrics=self.metrics, pos_label=self.conf.pos_label, tagging_scheme=problem.tagging_scheme, label_indices=None)
            elif ProblemTypes[self.problem.problem_type] == ProblemTypes.mrc:
                curr_mrc_metric = []
                for single_mrc_metric in self.metrics:
                    if 'mrc' in single_mrc_metric.lower():
                        curr_mrc_metric.append(single_mrc_metric.lower())
                    else:
                        curr_mrc_metric.append('mrc_' + single_mrc_metric.lower())
                self.evaluator = Evaluator(metrics=curr_mrc_metric, pos_label=self.conf.pos_label, tagging_scheme=problem.tagging_scheme, label_indices=None)
        self.use_gpu = use_gpu

        self.best_test_result = "(No best test result yet)" 
开发者ID:microsoft,项目名称:NeuronBlocks,代码行数:62,代码来源:LearningMachine.py


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