- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
问题
使用 Tensorflow 的 partial_run() 方法没有像我预期的那样工作。我在所提供代码的底部使用它,我相信它会给我附加的错误。
一般的数据流是我需要从模型中获得预测,在一些非 tensorflow 代码中使用该预测(对软件合成器进行编程),然后在播放后获得音频特征(MFCCS、RMS、FFT)一个 MIDI 音符,它最终可以传递给成本函数,以检查预测的音色与重新创建作为当前示例提供的所需声音的接近程度。
代码 - 省略预处理
# Create the tensorflow graph.
dimension_data_example = generate_examples(1,
midi_note,
midi_velocity,
note_length,
render_length,
engine,
generator,
mfcc_normaliser,
rms_normaliser)
features, parameters = dimension_data_example[0]
# https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/recurrent_network.ipynb
# Parameters for the tensorflow graph.
learning_rate = 0.001
training_iters = 256
batch_size = 128
display_step = 10
number_hidden_1 = 128
number_hidden_2 = 128
# Network parameters:
# 14 * 181 - (amount of mfccs + rms value) * sample size
number_input = int(features.shape[0])
# 155 - amount of parameters
number_outputs = len(parameters)
x = tf.placeholder("float", [None, number_input])
# Create model
def multilayer_perceptron(x, weights, biases):
# Hidden layer with RELU activation
layer_1 = tf.add(tf.matmul(x, weights['h1']), biases['b1'])
layer_1 = tf.nn.relu(layer_1)
# Hidden layer with RELU activation
layer_2 = tf.add(tf.matmul(layer_1, weights['h2']), biases['b2'])
layer_2 = tf.nn.relu(layer_2)
# Output layer with linear activation
out_layer = tf.matmul(layer_2, weights['out']) + biases['out']
return out_layer
# Store layers weight & bias
weights = {
'h1': tf.Variable(tf.random_normal([number_input, number_hidden_1])),
'h2': tf.Variable(tf.random_normal([number_hidden_1, number_hidden_2])),
'out': tf.Variable(tf.random_normal([number_hidden_2, number_outputs]))
}
biases = {
'b1': tf.Variable(tf.random_normal([number_hidden_1])),
'b2': tf.Variable(tf.random_normal([number_hidden_2])),
'out': tf.Variable(tf.random_normal([number_outputs]))
}
# Construct model
prediction = multilayer_perceptron(x, weights, biases)
x_original = tf.placeholder("float", [None, number_input])
x_from_y = tf.placeholder("float", [None, number_input])
cost = tf.sqrt(tf.reduce_mean(tf.square(tf.sub(x_original, x_from_y))))
optimiser = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)
# Initializing the variables
init = tf.global_variables_initializer()
# Launching the graph
with tf.Session() as sess:
sess.run(init)
step = 1
while step * batch_size < training_iters:
train_batch = generate_examples(batch_size,
midi_note,
midi_velocity,
note_length,
render_length,
engine,
generator,
mfcc_normaliser,
rms_normaliser)
split_train = map(list, zip(*train_batch))
batch_x = split_train[0]
setup = sess.partial_run_setup([prediction, optimiser],
[x, x_original, x_from_y])
pred = sess.partial_run(setup, prediction, feed_dict={x: batch_x})
features_from_prediction = get_features(pred,
midi_note,
midi_velocity,
note_length,
render_length)
sess.partial_run(setup, optimiser, feed_dict={x_original: batch_x,
x_from_y: features_from_prediction})
错误
Traceback (most recent call last):
File "model.py", line 255, in <module>
optimiser = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/optimizer.py", line 276, in minimize
([str(v) for _, v in grads_and_vars], loss))
ValueError: No gradients provided for any variable, check your graph for ops that do not support gradients, between variables ['Tensor("Variable/read:0", shape=(2534, 128), dtype=float32)', 'Tensor("Variable_1/read:0", shape=(128, 128), dtype=float32)', 'Tensor("Variable_2/read:0", shape=(128, 155), dtype=float32)', 'Tensor("Variable_3/read:0", shape=(128,), dtype=float32)', 'Tensor("Variable_4/read:0", shape=(128,), dtype=float32)', 'Tensor("Variable_5/read:0", shape=(155,), dtype=float32)'] and loss Tensor("Sqrt:0", shape=(), dtype=float32).
最佳答案
您遇到的直接错误:
No gradients provided for any variable, check your graph for ops that do not support gradients, between variables
是因为没有从您的成本
到您的权重的梯度路径。这是因为在权重和成本之间的图形之外发生了占位符和计算。因此,不存在从成本到权重的梯度路径。
换句话说,考虑设置。
Weights -> prediction -> get_features -> calculate cost.
现在,考虑反向传播,我们可以计算成本的梯度,但是我们没有从成本到 get_features 或从 get_features 到预测的梯度,因为 get_features 不是图的一部分:
Weights <- prediction <-/- get_features <-/- calculate cost.
因此,权重将永远无法学习。如果您希望此设置起作用,您需要以某种方式找到一条从成本返回到预测的路径,可能是在图形的反向路径中模拟 get_features 的梯度。可能有更简洁的方法,但我现在想不出一个。
希望对您有所帮助!
关于python - TensorFlow: "No gradients provided for any variable"和 partial_run,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42498876/
正在复制的问题是,当sew呈现登录页面时,然后我们继续执行身份验证,现在将我们重定向到网站的仪表板,此时我们继续关闭会话,并且在之前的交互中生成的这些cookie没有被删除。这个问题是重复性的,并且一
我是 Flutter 的新手,目前正在研究 DI。 我正在使用 flutter_bloc 和 provider 包。 flutter_bloc 附带一个 RepositoryProvider,我现在问
我是 Flutter 的新手,目前正在研究 DI。 我正在使用 flutter_bloc 和 provider 包。 flutter_bloc 附带一个 RepositoryProvider,我现在问
我正在使用 Angular2 开发一个应用程序。 我正在尝试在我的应用程序中使用 Reactive Forms,但我遇到了一些错误: 第一个错误是关于 NgControl 的,如下所示: No pro
最近很多用户在使用电脑的时候发现了wmi provider host进程占用内存比较大,不知道这个进程到底是干什么的,能不能禁止,怎么禁止。下面来一起看看想想的介绍吧。 wmi provide
我的问题是: 当我在设计时不知道这些表达式的数量和类型时,如何将列表中的表达式拼接成一个引用? 在底部,我包含了类型提供程序的完整代码。 (我已经剥离了这个概念来证明这个问题。)我的问题出现在这些行:
我目前正在学习使用 Flutter 进行应用程序开发,并已开始学习 Provider 包。我遇到了一些困难并收到错误: “在此...小部件之上找不到正确的提供者” 我最终移动了 Provider 小部
我是 android 的新手,我正在学习如何使用 JavaMail API 发送电子邮件的教程,我已经正确添加了必要的 Jar,但我总是遇到无法解析 GmailSender 类上的符号提供程序,我尝试
我正在我的 Angular 应用程序中进行单元测试,我正在使用 TestBed 方法, 我正在测试组件,所以每个规范文件看起来像这样 import... describe('AppComponent'
enter image description here 代码:这是我的 index.js 文件 index.js import { Provider } from "react-redux"
Microsoft ASP.NET Universal Providers 1.1昨天与System.Web.Providers 1.2一起发布.在后面的 nuget 页面上声明:Legacy pac
在我的 Next js 项目中,我使用了 Next auth,其中 import {Provider} from 'next-auth/client' , 并包裹 在 _app.js 中。 但是,与此
当我在 View 模型中使用如下界面时 class MainViewModel @ViewModelInject constructor( private val trafficImagesR
更新 - 我实际上发现它是 Flutter Issue . 我有两个 Provider,一个是 EntriesProvider,另一个是 EntryProvider。我在创建条目时使用我的 Entry
function configure($provide, $injector) { $provide.provider("testservice", function () {
这真让我抓狂。我似乎无法弄清楚这有什么问题。 代码: public interface IMinutesCounter { void startTimer(); void stopTi
我在我的项目中玩 Dagger 2,然后我陷入了这个错误编译。-> Error:(18, 21) error: ....MyManager cannot be provided without an
我有一个 Resteasy 应用程序,它使用 Spring 并包含 ContainerRequestFilter 和 ContainerResponseFilter 实现,并用 @Provider 注
我正在尝试使用 Dagger2 设置一个新项目,我以前使用过 Dagger2,但现在我正在尝试自己从头开始设置它。我正在从我参与的 Kotlin 项目中获取示例,但无法像现在在 Kotlin 中一样为
我刚开始学习 dagger2,遇到了一个奇怪的问题,在我看来像是一个错误。这是模块: @Module public class SimpleModule { @Provides Coo
我是一名优秀的程序员,十分优秀!