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


Python models.model_from_config方法代码示例

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


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

示例1: _instantiate

# 需要导入模块: from keras import models [as 别名]
# 或者: from keras.models import model_from_config [as 别名]
def _instantiate(self, rsc):

        # First, load the pump
        with open(resource_filename(__name__,
                                    os.path.join(rsc, 'pump.pkl')),
                  'rb') as fd:
            self.pump = pickle.load(fd)

        # Now load the model
        with open(resource_filename(__name__,
                                    os.path.join(rsc, 'model_spec.pkl')),
                  'rb') as fd:
            spec = pickle.load(fd)
            self.model = model_from_config(spec,
                                           custom_objects={k: layers.__dict__[k]
                                                           for k in layers.__all__})

        # And the model weights
        self.model.load_weights(resource_filename(__name__,
                                                  os.path.join(rsc,
                                                               'model.h5')))

        # And the version number
        with open(resource_filename(__name__,
                                    os.path.join(rsc, 'version.txt')),
                  'r') as fd:
            self.version = fd.read().strip() 
开发者ID:bmcfee,项目名称:crema,代码行数:29,代码来源:base.py

示例2: clone_model

# 需要导入模块: from keras import models [as 别名]
# 或者: from keras.models import model_from_config [as 别名]
def clone_model(model, custom_objects={}):
    # Requires Keras 1.0.7 since get_config has breaking changes.
    config = {
        'class_name': model.__class__.__name__,
        'config': model.get_config(),
    }
    clone = model_from_config(config, custom_objects=custom_objects)
    clone.set_weights(model.get_weights())
    return clone 
开发者ID:keras-rl,项目名称:keras-rl,代码行数:11,代码来源:util.py

示例3: clone_model

# 需要导入模块: from keras import models [as 别名]
# 或者: from keras.models import model_from_config [as 别名]
def clone_model(model, custom_objects=None):
    from keras.models import model_from_config
    custom_objects = custom_objects or {}
    config = {
        'class_name': model.__class__.__name__,
        'config': model.get_config(),
    }
    clone = model_from_config(config, custom_objects=custom_objects)
    clone.set_weights(model.get_weights())
    return clone


# clone a keras optimizer without file I/O 
开发者ID:kengz,项目名称:openai_lab,代码行数:15,代码来源:util.py

示例4: convert

# 需要导入模块: from keras import models [as 别名]
# 或者: from keras.models import model_from_config [as 别名]
def convert(prevmodel,export_path,freeze_graph_binary):

   # open up a Tensorflow session
   sess = tf.Session()
   # tell Keras to use the session
   K.set_session(sess)

   # From this document: https://blog.keras.io/keras-as-a-simplified-interface-to-tensorflow-tutorial.html
   
   # let's convert the model for inference
   K.set_learning_phase(0)  # all new operations will be in test mode from now on
   # serialize the model and get its weights, for quick re-building
   previous_model = load_model(prevmodel)
   previous_model.summary()

   config = previous_model.get_config()
   weights = previous_model.get_weights()

   # re-build a model where the learning phase is now hard-coded to 0
   try:
     model= Sequential.from_config(config) 
   except:
     model= Model.from_config(config) 
   #model= model_from_config(config)
   model.set_weights(weights)

   print("Input name:")
   print(model.input.name)
   print("Output name:")
   print(model.output.name)
   output_name=model.output.name.split(':')[0]

   #  not sure what this is for
   export_version = 1 # version number (integer)

   graph_file=export_path+"_graph.pb"
   ckpt_file=export_path+".ckpt"
   # create a saver 
   saver = tf.train.Saver(sharded=True)
   tf.train.write_graph(sess.graph_def, '', graph_file)
   save_path = saver.save(sess, ckpt_file)
#~/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph --input_graph=./graph.pb  --input_checkpoint=./model.ckpt --output_node_names=add_72 --output_graph=frozen.pb
   command = freeze_graph_binary +" --input_graph=./"+graph_file+" --input_checkpoint=./"+ckpt_file+" --output_node_names="+output_name+" --output_graph=./"+export_path+".pb"
   print(command)
   os.system(command) 
开发者ID:alanswx,项目名称:keras_to_tensorflow,代码行数:47,代码来源:convertkeras.py


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