- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 tensorflow 中,我需要从 inception_v3 预训练模型加载权重,以便在以下代码中使用:
with tf.variable_scope(scope, "InceptionV3", [images]) as scope:
with slim.arg_scope(
[slim.conv2d, slim.fully_connected],
weights_regularizer=weights_regularizer,
trainable=False):
with slim.arg_scope(
[slim.conv2d],
weights_initializer=tf.truncated_normal_initializer(stddev=stddev),
activation_fn=tf.nn.relu,
normalizer_fn=slim.batch_norm,
normalizer_params=batch_norm_params):
net, end_points = inception_v3_base(images, scope=scope)
with tf.variable_scope("logits"):
shape = net.get_shape()
net = slim.avg_pool2d(net, shape[1:3], padding="VALID", scope="pool")
net = slim.dropout(
net,
keep_prob=dropout_keep_prob,
is_training=False,
scope="dropout")
net = slim.flatten(net, scope="flatten")
image_embeddings = tf.contrib.layers.fully_connected(
inputs=net,
num_outputs=512,
activation_fn=None,
weights_initializer=initializer,
biases_initializer=None,
scope=scope)
如何才能做到这一点?您能举个简单的例子吗?
上面的代码中有两个权重初始值设定项。我不知道我必须在哪一个模型中初始化权重,以及如何初始化?
谢谢
最佳答案
TL;DR:阅读下面列表中的第三点。
每当您需要从检查点加载权重时,您都需要匹配的模型定义才能在尝试恢复权重之前定义图形。这是必要的,因为检查点文件仅包含变量的值,它没有有关图本身结构的信息。
模型结构可以通过不同的方式检索:
检查点附带一个匹配的 .meta
文件。在这种情况下,导入元图,然后通过以下方式恢复权重:
new_saver = tf.train.import_meta_graph('my-save-dir/my-model-10000.meta')
new_saver.restore(sess, 'my-save-dir/my-model-10000')
检查点附带一个匹配的 .pb
/.pbtxt
文件,其中包含序列化的 GraphDef
。在这种情况下,从其定义加载图表,然后恢复权重:
对于.pbtxt
:
with open('graph.pbtxt', 'r') as f:
graph_def = tf.GraphDef()
file_content = f.read()
text_format.Merge(file_content, graph_def)
tf.import_graph_def(graph_def, name='')
saver = tf.train.Saver() # note: it is important that this is defined AFTER you import the graph definition or it won't find any variables in the graph to restore
saver.restore(sess, "/tmp/model.ckpt")
对于.pb
:
with gfile.FastGFile('graph.pb','rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def, name='')
saver = tf.train.Saver() # note: it is important that this is defined AFTER you import the graph definition or it won't find any variables in the graph to restore
saver.restore(sess, "/tmp/model.ckpt")
检查点附带一个包含模型定义的匹配 python 文件。在这种情况下,请通读该文件的文档并找到需要调用来定义模型的函数。然后,在脚本中导入该函数,在定义saver
之前调用它,然后从检查点恢复变量的值:
from inception_v3 import inception_v3
logits, endpoints = inception_v3()
saver = tf.train.Saver() # as above, it is important that this is defined after you define the graph, or it won't find any variables.
saver.restore(sess, 'inception_v3.ckpt')
注意:对于这种情况,您需要完全调用保存检查点时调用的函数(除非您有选择地渴望恢复某些变量),否则恢复将失败并出现错误。
关于python - 在 tensorflow 中初始化 inception_v3.ckpt 的权重,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48496552/
我有几个系统,其中包含用户表以及某种形式的业力/权重/声誉。有时是用户发布的帖子数量,有时是用户在网站上的所有事件中收到的赞成/反对票数。 USER { id int name str
我需要能够使用填充的相对大小 - 根据设备的分辨率和 dpi 变大或变小。 例如,如果我的 View 宽度为 100 像素,我希望左侧填充 10 像素,右侧填充 10 像素。但是,如果它在更高密度的屏
我目前正在使用由大约 10 个字段组成的 Solr 索引数据。当我执行搜索时,我希望某些字段的权重更高。谁能帮我指出正确的方向? 例如,在所有字段中搜索“超人”等术语时,应在“Description”
我正在使用 igraph 模拟网络随时间的变化在 r并且我正在寻找一种有效且可扩展的方式来对此进行编码以用于业务。 网络变化的主要驱动因素是: 新增节点 新领带 新节点权重 在第一阶段,在 100 个
我一直在寻找一种使用OpenVINO框架上的C++ API获取网络每一层权重/参数和偏差张量的方法。我在文档中找不到任何内容,在示例中也找不到任何示例。我如何提取这些张量? 谢谢, 塞萨尔 编辑: 分
我的问题与 PHP Memcache 扩展的 addServer 函数中的“weight”参数有关。 在过去的几个月里,我一直在为所有服务器使用“weight = 1”。我现在正在尝试应用以下配置以最
我应该使用哪种数据结构来保持元素按给定权重排序?我需要在集合中添加元素,其中每个元素都会生成特定的权重,但该权重不包含(也不计算)在元素本身内部;它是由元素之外的其他人计算的。而且,权重不需要存储(但
我正在尝试在 keras/tensorflow 中使用具有多个类的焦点损失,这导致使用我猜的分类焦点损失。我找到了一些实现here和 there或there 。 据我了解,焦点损失中的参数a主要用于二
我有一个像这样的 Pandas 数据框: df = pd.DataFrame({'id': [121, 34324, 111, 12, 45, 232], 'weight'
我有一个带有输出神经元的神经网络,我想在软最大化之前使用经过训练的权重进行线性缩放。 我有 10 个输出,我想要 10 个权重,在输出被软最大化之前乘以每个输出。因此每个输出的权重为 1。 但我不断收
我有这样的布局: 我希望它看起来像: TextView - 宽度的 40%,带 ImageView 的布局
这让我彻底疯了。我想在 android 中使用有点复杂的布局。我正在尝试使用权重而不是固定事物的大小。也许我应该放弃…… 这是我想做的: 我想要 3 个 ScrollView (里面有 TextVie
我正在尝试开发类似于网格但使用 LinearLayout。我想在单行中有 3 张图像和图像后的确切底部文本。 我尝试过的: LinearLayout layout = new LinearLayout
我想在同一行添加一个 EditText 和一个 Button,我想将 80% 的行给 editText,20% 给 Button。 这是我的代码:
我有一个 mysql 表,其中存储一列(称为 tickets),并且 tickets 值可以是任意数字。 我想要做的是有一个mysql查询,从列中选择所有行,按降序对它们进行排序,然后使用PHP对查询
我搜索了一段时间,但结果让我很困惑,因为我对 MySQL 还很陌生。 我有一个包含这 4 列的表:AUTO_INCREMENT ID、NAME、TYPE、CHANCE 所以行看起来像这样: 1, NO
我不完全是 JS 专业人士,虽然不漂亮或高效,但这是有效的。 实际上,我在表单中有重复的字段组,并允许用户根据需要将数据从第一个字段复制到所有 5 个字段。 如何使这段代码更高效? function
我正在使用xgboost库来训练二元分类器。我想通过向权重添加噪声(例如集合中树的叶节点的值)来防止训练算法的数据泄漏。为此,我需要检索每棵树的权重并修改它们。 我可以通过在 Booster 对象上使
我正在尝试让 LinearLayout 中的 View 填充宽度。我尝试使用 LayoutParams 设置它,但它给了我一个错误: 我的代码: EditText et = new EditText(
我想改变 ScrollView 的权重,但找不到实现它的方法。 这是我的 XML: **other layout.. 从代码中只能设置scrollView的高度或者宽度,weigh
我是一名优秀的程序员,十分优秀!