本文整理汇总了Python中tensorflow.contrib.slim.nets.resnet_v1.resnet_v1_50方法的典型用法代码示例。如果您正苦于以下问题:Python resnet_v1.resnet_v1_50方法的具体用法?Python resnet_v1.resnet_v1_50怎么用?Python resnet_v1.resnet_v1_50使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.slim.nets.resnet_v1
的用法示例。
在下文中一共展示了resnet_v1.resnet_v1_50方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from tensorflow.contrib.slim.nets import resnet_v1 [as 别名]
# 或者: from tensorflow.contrib.slim.nets.resnet_v1 import resnet_v1_50 [as 别名]
def setUp(self):
tf.reset_default_graph()
self.nbclasses = 1000
inputs = tf.placeholder(tf.float32, [1, 224, 224, 3])
with slim.arg_scope(resnet_v1.resnet_arg_scope()):
net, end_points = resnet_v1.resnet_v1_50(inputs, self.nbclasses, is_training=False)
saver = tf.train.Saver(tf.global_variables())
check_point = 'test/data/resnet_v1_50.ckpt'
sess = tf.InteractiveSession()
saver.restore(sess, check_point)
conv_name = 'resnet_v1_50/block4/unit_3/bottleneck_v1/Relu'
self.graph_origin = tf.get_default_graph().as_graph_def()
self.insp = darkon.Gradcam(inputs, self.nbclasses, conv_name)
self.sess = sess
示例2: video_model
# 需要导入模块: from tensorflow.contrib.slim.nets import resnet_v1 [as 别名]
# 或者: from tensorflow.contrib.slim.nets.resnet_v1 import resnet_v1_50 [as 别名]
def video_model(video_frames=None, audio_frames=None):
"""Creates the video model.
Args:
video_frames: A tensor that contains the video input.
audio_frames: not needed (leave None).
Returns:
The video model.
"""
with tf.variable_scope("video_model"):
batch_size, seq_length, height, width, channels = video_frames.get_shape().as_list()
video_input = tf.reshape(video_frames, (batch_size * seq_length, height, width, channels))
video_input = tf.cast(video_input, tf.float32)
features, end_points = resnet_v1.resnet_v1_50(video_input, None)
features = tf.reshape(features, (batch_size, seq_length, int(features.get_shape()[3])))
return features
示例3: det_lesion_resnet
# 需要导入模块: from tensorflow.contrib.slim.nets import resnet_v1 [as 别名]
# 或者: from tensorflow.contrib.slim.nets.resnet_v1 import resnet_v1_50 [as 别名]
def det_lesion_resnet(inputs, is_training_option=False, scope='det_lesion'):
"""Defines the network
Args:
inputs: Tensorflow placeholder that contains the input image
scope: Scope name for the network
Returns:
net: Output Tensor of the network
end_points: Dictionary with all Tensors of the network
"""
with tf.variable_scope(scope, 'det_lesion', [inputs]) as sc:
end_points_collection = sc.name + '_end_points'
with slim.arg_scope(resnet_v1.resnet_arg_scope()):
net, end_points = resnet_v1.resnet_v1_50(inputs, is_training=is_training_option)
net = slim.flatten(net, scope='flatten5')
net = slim.fully_connected(net, 1, activation_fn=tf.nn.sigmoid,
weights_initializer=initializers.xavier_initializer(), scope='output')
utils.collect_named_outputs(end_points_collection, 'det_lesion/output', net)
end_points = slim.utils.convert_collection_to_dict(end_points_collection)
return net, end_points
示例4: load_resnet_imagenet
# 需要导入模块: from tensorflow.contrib.slim.nets import resnet_v1 [as 别名]
# 或者: from tensorflow.contrib.slim.nets.resnet_v1 import resnet_v1_50 [as 别名]
def load_resnet_imagenet(ckpt_path):
"""Initialize the network parameters from the Resnet-50 pre-trained model provided by TF-SLIM
Args:
Path to the checkpoint
Returns:
Function that takes a session and initializes the network
"""
reader = tf.train.NewCheckpointReader(ckpt_path)
var_to_shape_map = reader.get_variable_to_shape_map()
vars_corresp = dict()
for v in var_to_shape_map:
if "bottleneck_v1" in v or "conv1" in v:
vars_corresp[v] = slim.get_model_variables(v.replace("resnet_v1_50", "det_lesion/resnet_v1_50"))[0]
init_fn = slim.assign_from_checkpoint_fn(ckpt_path, vars_corresp)
return init_fn
示例5: test_resnet
# 需要导入模块: from tensorflow.contrib.slim.nets import resnet_v1 [as 别名]
# 或者: from tensorflow.contrib.slim.nets.resnet_v1 import resnet_v1_50 [as 别名]
def test_resnet(self):
with slim.arg_scope(resnet_v1.resnet_arg_scope()):
net, end_points = resnet_v1.resnet_v1_50(self.inputs, self.nbclasses, is_training=False)
saver = tf.train.Saver(tf.global_variables())
check_point = 'test/data/resnet_v1_50.ckpt'
sess = tf.InteractiveSession()
saver.restore(sess, check_point)
self.sess = sess
self.graph_origin = tf.get_default_graph()
self.target_op_name = darkon.Gradcam.candidate_featuremap_op_names(sess, self.graph_origin)[-1]
self.model_name = 'resnet'
self.assertEqual('resnet_v1_50/block4/unit_3/bottleneck_v1/Relu', self.target_op_name)
示例6: build_graph
# 需要导入模块: from tensorflow.contrib.slim.nets import resnet_v1 [as 别名]
# 或者: from tensorflow.contrib.slim.nets.resnet_v1 import resnet_v1_50 [as 别名]
def build_graph(self, orig_image):
mean = tf.get_variable('resnet_v1_50/mean_rgb', shape=[3])
with guided_relu():
with slim.arg_scope(resnet_v1.resnet_arg_scope()):
image = tf.expand_dims(orig_image - mean, 0)
logits, _ = resnet_v1.resnet_v1_50(image, 1000, is_training=False)
saliency_map(logits, orig_image, name="saliency")