本文整理汇总了Python中model.model_fn方法的典型用法代码示例。如果您正苦于以下问题:Python model.model_fn方法的具体用法?Python model.model_fn怎么用?Python model.model_fn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model
的用法示例。
在下文中一共展示了model.model_fn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: experiment
# 需要导入模块: import model [as 别名]
# 或者: from model import model_fn [as 别名]
def experiment():
train_input_fn = generate_input_fn(
is_train=True,
tfrecords_path=config.tfrecords_path,
batch_size=config.batch_size,
time_step=config.time_step)
eval_input_fn = generate_input_fn(
is_train=False,
tfrecords_path=config.tfrecords_path,
batch_size=config.batch_size_eval,
time_step=config.time_step_eval)
estimator = Estimator(
train_input_fn=train_input_fn,
eval_input_fn=eval_input_fn,
model_fn=model_fn)
estimator.train()
示例2: export_savedmodel
# 需要导入模块: import model [as 别名]
# 或者: from model import model_fn [as 别名]
def export_savedmodel():
config = tf.ConfigProto()
config.gpu_options.visible_device_list = GPU_TO_USE
run_config = tf.estimator.RunConfig()
run_config = run_config.replace(
model_dir=params['model_dir'],
session_config=config
)
params['nms_max_output_size'] = NMS_MAX_OUTPUT_SIZE
estimator = tf.estimator.Estimator(model_fn, params=params, config=run_config)
def serving_input_receiver_fn():
raw_images = tf.placeholder(dtype=tf.uint8, shape=[BATCH_SIZE, None, None, 3], name='images')
w, h = tf.shape(raw_images)[2], tf.shape(raw_images)[1]
with tf.device('/gpu:0'):
images = tf.to_float(raw_images)
if RESIZE:
images = tf.squeeze(images, 0)
images = resize_keeping_aspect_ratio(images, MIN_DIMENSION, MAX_DIMENSION)
images = tf.expand_dims(images, 0)
features = {
'images': (1.0/255.0) * images,
'images_size': tf.stack([w, h])
}
return tf.estimator.export.ServingInputReceiver(features, {'images': raw_images})
shutil.rmtree(OUTPUT_FOLDER, ignore_errors=True)
os.mkdir(OUTPUT_FOLDER)
estimator.export_savedmodel(OUTPUT_FOLDER, serving_input_receiver_fn)