- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用 TensorFlow 实现了具有一个隐藏层的多层感知器 (MLP),但在调用该函数时出现以下错误。任何帮助将不胜感激。
def MLP(x, option, dropout=1, prefix ='', num_outputs=1, reuse=None):
weights = tf.random_uniform_initializer(-0.001, 0.001)
biases = tf.constant_initializer(0.001, dtype=tf.float32)
fc1 = tf.contrib.layers.fully_connected(tf.nn.dropout(x, keep_prob=dropout),
num_outputs=option.num_outputs,
biases_initializer=biases,
weights_initializer = weights,
activation_fn=tf.nn.relu,
scope=prefix + 'fc',
reuse=reuse)
logits = tf.contrib.layers.linear(tf.nn.dropout(fc1, keep_prob=dropout),
num_outputs=num_outputs,
biases_initializer=biases,
weights_initializer = weights,
scope=prefix + 'l',
reuse=reuse)
return logits
logits = MLP(x, option, dropout=dp, prefix='mlp-', reuse=True)
ValueError:变量 mlp-fc/weights 不存在,或者不是用 tf.get_variable() 创建的。您是要在 VarScope 中设置 reuse=tf.AUTO_REUSE 吗?
我尝试初始化权重并设置 weights_initializer 但仍然出现相同的错误。
最佳答案
错误是因为您试图重用名为'mlp-fc/weights'的权重,它不存在。
同样的错误也可能适用于您的 tf.contrib.layers.linear。
为了重用,您首先必须定义它们。
但是,如果您不想重用任何可变权重,您可以简单地从这两种方法中删除reuse= True,tf.contrib.layers .fully_connected 和 tf.contrib.layers.linear。
编辑
您可以使用类似于以下代码的内容。
with tf.variable_scope("mlp-fc"):
#add a new variable to the graph
var=tf.get_variable("weights",shape)
可以关注这篇文章到https://jasdeep06.github.io/posts/variable-sharing-in-tensorflow/了解有关重用的更多信息。
希望这对您有所帮助。
关于python - ValueError : Variable mlp-fc/weights does not exist, 或不是用 tf.get_variable() 创建的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49376603/
我想使用简单的 MLP 模型进行迁移学习。首先,我在大数据上训练 1 个隐藏层前馈网络: net = Sequential() net.add(Dense(500, input_dim=2048, k
最近我正在使用 Tensorflow。我正在探索如何在 Tensorflow 中实现多层感知器。 我在网上学习了很多教程。他们中的大多数使用一两个隐藏层。一个简单的例子取自 here def forw
我对机器学习非常陌生,正在尝试实现 MLP,但是成本函数似乎在达到全局最小值之前就达到了局部最小值。我将成本绘制为迭代函数(包括 0 值,以免被 y 轴的起始位置所迷惑)。 这是我尝试使用的代码: i
以下是我的 MLP 模型, layers = [10,20,30,40,50] model = keras.models.Sequential() #Stacking Layers model.add
我是机器学习的新手,我正在开发一个 python 应用程序,该应用程序使用数据集对扑克牌进行分类,我将发布片段。似乎效果不太好。它无法正确对手进行分类。我收到以下错误 ", line 298, in
我有这样的数据 有 29 列,我必须预测其中的 winPlacePerc(数据帧的最末端)在 1 之间(高百分比)到 0(低百分比) 在 29 列中,25 是数字 数据 3 是 ID(对象) 1 是
您好,我正在尝试修改 mnist 示例以使其与我的数据集相匹配。我只尝试使用 mlp 示例,但它给出了一个奇怪的错误。 数据集是一个有 2100 行和 17 列的矩阵,输出应该是 16 个可能的类别之
我在 Dlib 中创建了一个多层感知器网络: mlp::kernel_1a_c net(2,5); 输入层有 2 个节点,第一个隐藏层有 5 个节点。该网络是否已经包含偏置节点?还是必须自己添加? 最
我正在 matlab 中制作一个具有反向传播的 MLP 神经网络。问题是,它似乎无法很好地处理函数中的曲线,也无法很好地与值进行缩放。例如,它可以达到 cos(x) 的 80%,但如果我输入 100*
我是 OpenCV 世界和神经网络的新手,但我有一些 C++/Java 编码经验。 我创建了我的第一个 ANN MLP 并学习了 XOR: #include #include #include
给定输入特征,仅原始数字: tensor([0.2153, 0.2190, 0.0685, 0.2127, 0.2145, 0.1260, 0.1480, 0.1483, 0.1489,
我正在尝试使用简单的时间序列预测。给定数量的输入(1 分钟滴答) Net 应该尝试预测下一个。我用不同的设置训练了 3 个网络来说明我的问题: 在右侧,您可以看到 3 个训练器 MLP - 随机命名和
我正在运行 MLP 将一组值分为 10 个不同的类别。 简单来说,我有一个声纳,它可以提供 400 个物体的“读数”。每个读数都是 1000 个浮点值的列表。 我已扫描了总共 100 个对象,想要对它
我正在创建一个简单的神经网络,其中有一个隐藏层用于分类。 我的输入数据集已准备好并保存在 .t7 文件中。 input = { data : DoubleTensor - size: 1400x1
我设置了以下参数: parameter_space = { 'hidden_layer_sizes': [(sp_randint.rvs(100,600,1),sp_randint.rvs(1
我正在使用机器学习制作一个国际象棋引擎,但在调试它时遇到了问题。我需要帮助找出我的程序出了什么问题,如果有任何帮助,我将不胜感激。 我进行了研究,并从多个成功的项目中借鉴了想法。这个想法是使用强化学习
我正在学习机器学习,我看到一些 Material 表明MLP(多层感知器)可能会陷入局部最小值。我想通过做一些实验来学习,但我在网上搜索了具体的例子,但找不到任何例子。谁能告诉我在哪里可以找到可以由我
我(有点像初学者)在时间序列数据应用程序上尝试使用 Keras,我创建了一个回归模型,然后将其保存以在不同的 Python 脚本上运行。 我正在处理的时间序列数据是每小时数据,我使用 Keras 中保
我尝试使用 keras(支持 tensorflow )创建一个神经网络。我有 4 个输入变量和 2 个输出变量:不可用 我想对不可用的测试集进行预测。 这是我的代码: from keras impor
我使用 theano 编写了一个 MLP 分类器。使用反向传播算法的训练函数如下: self.weights=[theano.shared(numpy.random.random((network.a
我是一名优秀的程序员,十分优秀!