- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经解决了一些其他抛出的错误,但是在进行一些研究之前和之后我从未见过这个错误,我仍然不确定这里到底是什么问题或如何解决它。
我猜想在某个时候 reshape 数据是必需的,但我不明白为什么这是一个问题,或者 [1,2] 和 [1,1] 的大小实际上意味着什么。
输入到脚本中的数据是[128 x 128 x 128 ndarray,二进制标签]
我正在使用的代码是:
import tensorflow as tf
import numpy as np
import os
import math
# input arrays
x = tf.placeholder(tf.float32, [None, 128, 128, 128, 1])
# labels
y = tf.placeholder(tf.float32, None)
# learning rate
lr = tf.placeholder(tf.float32)
##### Code for ConvNet is here #####
# Data
INPUT_FOLDER = 'data/cubed_data/pp/labelled'
images = os.listdir(INPUT_FOLDER)
images.sort()
td = []
count = 1
for i in images:
im = np.load(INPUT_FOLDER + "/" + i)
data = im[0]
data = np.reshape(data, (128, 128, 128, 1))
label = im[1]
lbd = [data, label]
td.append(lbd)
test_data = td[:100]
train_data = td[100:]
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(logits=fc3l, labels=y)
correct_prediction = tf.equal(tf.argmax(probs, 1), tf.argmax(y, 0))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
train_step = tf.train.AdamOptimizer(lr).minimize(cross_entropy)
# init
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
def training_step(i, update_test_data, update_train_data):
for a in range(len(train_data)):
batch = train_data[a]
batch_x = batch[0]
batch_y = batch[1]
# learning rate decay
max_learning_rate = 0.003
min_learning_rate = 0.0001
decay_speed = 2000.0
learning_rate = min_learning_rate + (max_learning_rate - min_learning_rate) * math.exp(-i / decay_speed)
if update_train_data:
a, c = sess.run([accuracy, cross_entropy], {x: [batch_x], y: [batch_y]})
print(str(i) + ": accuracy:" + str(a) + " loss: " + str(c) + " (lr:" + str(learning_rate) + ")")
if update_test_data:
a, c = sess.run([accuracy, cross_entropy], {x: [test_data[0]], y: [test_data[1]]})
print(str(i) + ": ********* epoch " + " ********* test accuracy:" + str(a) + " test loss: " + str(c))
sess.run(train_step, {x: [batch_x], y: [batch_y], lr: learning_rate})
for q in range(10000 + 1):
training_step(q, q % 100 == 0, q % 20 == 0)
Invalid argument: logits and labels must be same size: logits_size=[1,2] labels_size=[1,1]
[[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](Reshape, Reshape_1)]]
Traceback (most recent call last):
File "/home/entelechy/tfenv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 972, in _do_call
return fn(*args)
File "/home/entelechy/tfenv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 954, in _run_fn
status, run_metadata)
File "/usr/lib/python3.5/contextlib.py", line 66, in __exit__
next(self.gen)
File "/home/entelechy/tfenv/lib/python3.5/site-packages/tensorflow/python/framework/errors.py", line 463, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors.InvalidArgumentError: logits and labels must be same size: logits_size=[1,2] labels_size=[1,1]
[[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](Reshape, Reshape_1)]]
[[Node: Reshape_2/_7 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_233_Reshape_2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tfvgg.py", line 293, in <module>
training_step(q, q % 100 == 0, q % 20 == 0)
File "tfvgg.py", line 282, in training_step
a, c = sess.run([accuracy, cross_entropy], {x: [batch_x], y: [batch_y]})
File "/home/entelechy/tfenv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 717, in run
run_metadata_ptr)
File "/home/entelechy/tfenv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 915, in _run
feed_dict_string, options, run_metadata)
File "/home/entelechy/tfenv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 965, in _do_run
target_list, options, run_metadata)
File "/home/entelechy/tfenv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 985, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors.InvalidArgumentError: logits and labels must be same size: logits_size=[1,2] labels_size=[1,1]
[[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](Reshape, Reshape_1)]]
[[Node: Reshape_2/_7 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_233_Reshape_2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Caused by op 'SoftmaxCrossEntropyWithLogits', defined at:
File "tfvgg.py", line 254, in <module>
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(logits=fc3l, labels=y)
File "/home/entelechy/tfenv/lib/python3.5/site-packages/tensorflow/python/ops/nn_ops.py", line 676, in softmax_cross_entropy_with_logits
precise_logits, labels, name=name)
File "/home/entelechy/tfenv/lib/python3.5/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 1744, in _softmax_cross_entropy_with_logits
features=features, labels=labels, name=name)
File "/home/entelechy/tfenv/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 749, in apply_op
op_def=op_def)
File "/home/entelechy/tfenv/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2380, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/home/entelechy/tfenv/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1298, in __init__
self._traceback = _extract_stack()
InvalidArgumentError (see above for traceback): logits and labels must be same size: logits_size=[1,2] labels_size=[1,1]
[[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](Reshape, Reshape_1)]]
[[Node: Reshape_2/_7 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_233_Reshape_2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
最佳答案
仔细观察后,我发现问题是第三个全连接层的输出是 2 个类,当标签是单个类的二进制时。更改了最后一个全连接层中的代码以解决单个类,此错误已解决。
关于tensorflow - InvalidArgumentError : logits and labels must be same size: logits_size=[1, 2] labels_size=[1,1],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43274169/
我为句子分类的任务建立了卷积模型,并且模型编译成功。但是,当我尝试将模型与训练/验证数据集拟合时,下面出现奇怪的invalid argument error: InvalidArgumentError
我无法让 keras.backend.function 正常工作。我正在尝试关注这篇文章: How to calculate prediction uncertainty using Keras? 在
我正在尝试在 Keras 中训练一个简单的 LSTM。我的数据具有以下维度: train_x.shape, train_y.shape, test_x.shape, test_y.shape > ((
尝试创建一个非常简单的具有 2 个隐藏层的感知器,它可以学习 f 定义的函数。我遇到的问题(除了不知道我在做什么之外)是我得到了一个很长的堆栈跟踪(在底部) 我认为源自定义 y_ 的行。该错误的最后部
我在使用导出的 tensorflow 模型时遇到问题。它不允许我评估我提供的数据集。但是,如果我在与训练相同的 session 中运行评估,那么如果我必须重新训练我的模型只是为了使用另一个数据集进行测
我正在尝试使用 TensorFlow 训练我自己的图像(682x1024x3= 2095104 像素)。因此,我结合了几个已发布的脚本来 1) 使用 TFRecord 编写器创建一个 .tfrcord
我对 tensorflow 比较陌生,目前正在尝试不同复杂度的模型。我对包的保存和恢复功能有疑问。就我对教程的理解而言,我应该能够恢复经过训练的图形,并在以后使用一些新输入运行它。但是,当我尝试这样做
我开始加载和保存 tfrecord 文件,以编写输入函数。我已经设置了以下测试,但收到 InvalidArgumentError。我已经使用 save() 方法保存了 tfrecord 文件,并尝试使
我正在使用 Keras 后端函数来计算强化学习设置中的梯度,以下是代码片段。对于此代码,我也收到以下错误。可能是什么原因造成的? 1 X = K.placeholder(shape=(
我正在尝试从 here 运行 train.py 。它基于this tutorial 。我想找到混淆矩阵,并在 train.py 的最后一行之后添加: confusionMatrix = tf.conf
我正在使用 while_loop 迭代更新矩阵。对于密集张量,循环运行良好,但是当我使用稀疏张量时,出现以下错误: InvalidArgumentError: Number of rows of a_
我使用 tf.Keras 使用 1D 卷积层构建模型进行分类。如果我删除张量板,这会很好用。作为初学者,我无法弄清楚问题是什么。请帮忙 %reload_ext tensorboard import t
大家好,我是计算机视觉和分类方面的专家,我正在尝试使用带有 tensorflow 和 keras 的 cnn 方法来训练模型,但我一直收到此代码下方的错误,任何人都可以帮助我或至少给我一个和平的建议?
使用dynamic_rnn时的Tensorflow 1.7最初运行良好,但在第32步(运行代码时发生变化),出现错误。当我使用较小的批处理时,似乎代码可以运行更长的时间,但是错误仍然弹出。只是无法找出
我正尝试在调制上执行此示例笔记本 https://github.com/radioML/examples/blob/master/modulation_recognition/RML2016.10a_
model.fit 产生异常: tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot update variable
model.fit 产生异常: tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot update variable
我尝试在顺序 Keras 模型上调用 model.fit(),但收到此错误: -------------------------------------------------------------
我正在解决 TensorFlow 的示例问题(特别是使用占位符),并且不明白为什么我收到(看起来是)形状/类型错误,而我相当有信心这些错误是什么他们应该是。 我尝试过使用 X_batch 和 y_ba
我用tensorflow实现了一个语言模型。训练数据只是 feed_dict 中的很多句子,如下所示: feed_dict = { model.inputs: x, model.seq
我是一名优秀的程序员,十分优秀!