Ошибка тензорного потока: отрицательный размер, вызванный вычитанием

Я публикую этот вопрос, потому что аналогичный вопрос был опубликован для keras. Я получаю эту ошибку в tenorflow.

Мои данные имеют 8 столбцов функций и 1 столбец меток. Я использую размер окна 90. То же самое работает для 3 функций и 6 метки. Я искал, но не мог найти правильный ответ.

Я попробовал это, но не сработало

segments, labels = segment_signal(dataset)
labels = np.asarray(pd.get_dummies(labels), dtype=np.int8)
reshaped_segments = segments.reshape(len(segments), 1, 90, 8)

train_test_split = np.random.rand(len(reshaped_segments)) < 0.70
train_x = reshaped_segments[train_test_split]
train_y = labels[train_test_split]
test_x = reshaped_segments[~train_test_split]
test_y = labels[~train_test_split]

input_height = 1 # 1-Dimensional convulotion
input_width = 90 #window
num_labels = 4 #output labels
num_channels = 8 #input columns

batch_size = 10
kernel_size = 60
depth = 60
num_hidden = 1000

learning_rate = 0.0001
training_epochs = 1#8

total_batches = train_x.shape[0] # batch_size

X = tf.placeholder(tf.float32, shape=[None,input_height,input_width,num_channels],name="input")
# X = tf.placeholder(tf.float32, shape=[None,input_width * num_channels], name="input")
# X_reshaped = tf.reshape(X,[-1,1,90,3])
Y = tf.placeholder(tf.float32, shape=[None,num_labels])

c = apply_depthwise_conv(X,kernel_size,num_channels,depth)
p = apply_max_pool(c,20,2)
c = apply_depthwise_conv(p,8,depth*num_channels,depth//10)

shape = c.get_shape().as_list()
c_flat = tf.reshape(c, [-1, shape[1] * shape[2] * shape[3]])

f_weights_l1 = weight_variable([shape[1] * shape[2] * depth * num_channels * (depth//10), num_hidden])
f_biases_l1 = bias_variable([num_hidden])
f = tf.nn.tanh(tf.add(tf.matmul(c_flat, f_weights_l1),f_biases_l1))

out_weights = weight_variable([num_hidden, num_labels])
out_biases = bias_variable([num_labels])
y_ = tf.nn.softmax(tf.matmul(f, out_weights) + out_biases,name="y_")

loss = -tf.reduce_sum(Y * tf.log(y_))
optimizer = tf.train.GradientDescentOptimizer(learning_rate = learning_rate).minimize(loss)

correct_prediction = tf.equal(tf.argmax(y_,1), tf.argmax(Y,1)) #difference between correct output and expected output
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

cost_history = np.empty(shape=[1], dtype=float)


with tf.Session() as session:
    tf.global_variables_initializer().run()
    for epoch in range(training_epochs):
        for b in range(total_batches):
            offset = (b * batch_size) % (train_y.shape[0] - batch_size)
            batch_x = train_x[offset:(offset + batch_size), :, :, :]
            batch_y = train_y[offset:(offset + batch_size), :]
            _, c = session.run([optimizer, loss], feed_dict={X: batch_x, Y: batch_y})
            cost_history = np.append(cost_history, c)
        print "Epoch: ", epoch, " Training Loss: ", c, " Training Accuracy: ",
        session.run(accuracy, feed_dict={X: train_x, Y: train_y})
    print "Testing Accuracy:", session.run(accuracy, feed_dict={X: test_x, Y: test_y})

Я получил следующую ошибку:

/usr/bin/python2.7 /home/aawesh/PycharmProjects/CNN/ActivittyDetection.py
Traceback (most recent call last):
  File "/home/aawesh/PycharmProjects/CNN/ActivittyDetection.py", line 151, in <module>
    c = apply_depthwise_conv(p,8,depth*num_channels,depth//10)
  File "/home/aawesh/PycharmProjects/CNN/ActivittyDetection.py", line 90, in apply_depthwise_conv
    return tf.nn.relu(tf.add(depthwise_conv2d(x, weights), biases))
  File "/home/aawesh/PycharmProjects/CNN/ActivittyDetection.py", line 84, in depthwise_conv2d
    return tf.nn.depthwise_conv2d(x, W, [1, 1, 1, 1], padding='VALID')
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/nn_impl.py", line 461, in depthwise_conv2d
    op=op)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/nn_ops.py", line 365, in with_space_to_batch
    return new_op(input, None)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/nn_ops.py", line 521, in __call__
    return self.call(inp, filter)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/nn_ops.py", line 355, in <lambda>
    return lambda inp, _: op(inp, num_spatial_dims, padding)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/nn_impl.py", line 453, in op
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 1341, in depthwise_conv2d_native
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 3273, in create_op
    compute_device=compute_device)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 3313, in _create_op_helper
    set_shapes_for_outputs(op)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2501, in set_shapes_for_outputs
    return _set_shapes_for_outputs(op)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2474, in _set_shapes_for_outputs
    shapes = shape_func(op)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2404, in call_with_requiring
    return call_cpp_shape_fn(op, require_shape_fn=True)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/common_shapes.py", line 627, in call_cpp_shape_fn
    require_shape_fn)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/common_shapes.py", line 691, in _call_cpp_shape_fn_impl
    raise ValueError(err.message)
ValueError: Negative dimension size caused by subtracting 8 from 6 for 'depthwise_1' (op: 'DepthwiseConv2dNative') with input shapes: [?,1,6,480], [1,8,480,6].

Process finished with exit code 1

0 ответов

Другие вопросы по тегам