TENSORFLOW Cannot feed value of shape (10, 9) for Tensor 'Placeholder_2:0', which has shape '(?, 7)'











up vote
0
down vote

favorite












I am using Tensorflow to train my data for gesture recognition. Here is my Code:



import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
import tensorflow as tf

%matplotlib inline
plt.style.use('ggplot')

def read_data(file_path):
column_names = ['user-id','activity','timestamp','x-axis','y-axis','z-axis']
data = pd.read_csv(file_path,header = None, names = column_names, comment=';')
return data

def feature_normalize(dataset):
mu = np.mean(dataset,axis = 0)
sigma = np.std(dataset,axis = 0)
return (dataset - mu)/sigma

def plot_axis(ax, x, y, title):
ax.plot(x, y)
ax.set_title(title)
ax.xaxis.set_visible(False)
ax.set_ylim([min(y) - np.std(y), max(y) + np.std(y)])
ax.set_xlim([min(x), max(x)])
ax.grid(True)

def plot_activity(activity,data):
fig, (ax0, ax1, ax2) = plt.subplots(nrows = 3, figsize = (15, 10), sharex = True)
plot_axis(ax0, data['timestamp'], data['x-axis'], 'x-axis')
plot_axis(ax1, data['timestamp'], data['y-axis'], 'y-axis')
plot_axis(ax2, data['timestamp'], data['z-axis'], 'z-axis')
plt.subplots_adjust(hspace=0.2)
fig.suptitle(activity)
plt.subplots_adjust(top=0.90)
plt.show()

dataset = read_data('C:\Users\ASUS\Desktop\final_data.txt')
dataset['x-axis'] = feature_normalize(dataset['x-axis'])
dataset['y-axis'] = feature_normalize(dataset['y-axis'])
dataset['z-axis'] = feature_normalize(dataset['z-axis'])

for activity in np.unique(dataset["activity"]):
subset = dataset[dataset["activity"] == activity][:34]
plot_activity(activity,subset)

def windows(data, size):
start = 0
while start < data.count():
yield int(start), int(start + size)
start += (size / 2)

def segment_signal(data,window_size = 17):
segments = np.empty((0,window_size,3))
labels = np.empty((0))
for (start, end) in windows(data["timestamp"], window_size):
x = data["x-axis"][start:end]
y = data["y-axis"][start:end]
z = data["z-axis"][start:end]
if(len(dataset["timestamp"][start:end]) == window_size):
segments = np.vstack([segments,np.dstack([x,y,z])])
labels = np.append(labels,stats.mode(data["activity"][start:end])[0][0])
return segments, labels

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

train_test_split = np.random.rand(len(reshaped_segments)) < 0.80
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
input_width = 17
num_labels = 7
num_channels = 3

batch_size = 100
kernel_size = 5
depth = 60
num_hidden = 1000

learning_rate = 0.0001
training_epochs = 10

total_batchs = train_x.shape[0] // batch_size

def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev = 0.1)
return tf.Variable(initial)

def bias_variable(shape):
initial = tf.constant(0.0, shape = shape)
return tf.Variable(initial)

def depthwise_conv2d(x, W):
return tf.nn.depthwise_conv2d(x,W, [1, 1, 1, 1], padding='VALID')

def apply_depthwise_conv(x,kernel_size,num_channels,depth):
weights = weight_variable([1, kernel_size, num_channels, depth])
biases = bias_variable([depth * num_channels])
return tf.nn.relu(tf.add(depthwise_conv2d(x, weights),biases))

def apply_max_pool(x,kernel_size,stride_size):
return tf.nn.max_pool(x, ksize=[1, 1, kernel_size, 1],
strides=[1, 1, stride_size, 1], padding='VALID')

X = tf.placeholder(tf.float32, shape=[None,input_height,input_width,num_channels],name="Mul")
Y = tf.placeholder(tf.float32, shape=[None,num_labels])

c = apply_depthwise_conv(X,kernel_size,num_channels,depth)
p = apply_max_pool(c,4,2)
c = apply_depthwise_conv(p,3,depth*num_channels,depth//6)

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//6), num_hidden]) #10
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))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

saver = tf.train.Saver()
with tf.Session() as session:
tf.global_variables_initializer().run()
for epoch in range(training_epochs):
cost_history = np.empty(shape=[1],dtype=float)
for b in range(total_batchs):
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}))
tf.train.write_graph(session.graph_def, '.', '../har.pbtxt')
saver.save(session,save_path = "../har.ckpt")


In the last line encounter this error message



ValueError: Cannot feed value of shape (10, 9) for Tensor 'Placeholder_2:0', which has shape '(?, 7)'



I tried changing some values but still I cannot fix this error.



What can I do to resolve this error?










share|improve this question






















  • Since you feed a (10 x 9) tensor into Y = tf.placeholder(tf.float32, shape=[None,num_labels]), which has shape (batch_size, 7). You need to check the length of Y should be 7 or 9.
    – HaoChien Hung
    Nov 18 at 11:20















up vote
0
down vote

favorite












I am using Tensorflow to train my data for gesture recognition. Here is my Code:



import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
import tensorflow as tf

%matplotlib inline
plt.style.use('ggplot')

def read_data(file_path):
column_names = ['user-id','activity','timestamp','x-axis','y-axis','z-axis']
data = pd.read_csv(file_path,header = None, names = column_names, comment=';')
return data

def feature_normalize(dataset):
mu = np.mean(dataset,axis = 0)
sigma = np.std(dataset,axis = 0)
return (dataset - mu)/sigma

def plot_axis(ax, x, y, title):
ax.plot(x, y)
ax.set_title(title)
ax.xaxis.set_visible(False)
ax.set_ylim([min(y) - np.std(y), max(y) + np.std(y)])
ax.set_xlim([min(x), max(x)])
ax.grid(True)

def plot_activity(activity,data):
fig, (ax0, ax1, ax2) = plt.subplots(nrows = 3, figsize = (15, 10), sharex = True)
plot_axis(ax0, data['timestamp'], data['x-axis'], 'x-axis')
plot_axis(ax1, data['timestamp'], data['y-axis'], 'y-axis')
plot_axis(ax2, data['timestamp'], data['z-axis'], 'z-axis')
plt.subplots_adjust(hspace=0.2)
fig.suptitle(activity)
plt.subplots_adjust(top=0.90)
plt.show()

dataset = read_data('C:\Users\ASUS\Desktop\final_data.txt')
dataset['x-axis'] = feature_normalize(dataset['x-axis'])
dataset['y-axis'] = feature_normalize(dataset['y-axis'])
dataset['z-axis'] = feature_normalize(dataset['z-axis'])

for activity in np.unique(dataset["activity"]):
subset = dataset[dataset["activity"] == activity][:34]
plot_activity(activity,subset)

def windows(data, size):
start = 0
while start < data.count():
yield int(start), int(start + size)
start += (size / 2)

def segment_signal(data,window_size = 17):
segments = np.empty((0,window_size,3))
labels = np.empty((0))
for (start, end) in windows(data["timestamp"], window_size):
x = data["x-axis"][start:end]
y = data["y-axis"][start:end]
z = data["z-axis"][start:end]
if(len(dataset["timestamp"][start:end]) == window_size):
segments = np.vstack([segments,np.dstack([x,y,z])])
labels = np.append(labels,stats.mode(data["activity"][start:end])[0][0])
return segments, labels

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

train_test_split = np.random.rand(len(reshaped_segments)) < 0.80
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
input_width = 17
num_labels = 7
num_channels = 3

batch_size = 100
kernel_size = 5
depth = 60
num_hidden = 1000

learning_rate = 0.0001
training_epochs = 10

total_batchs = train_x.shape[0] // batch_size

def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev = 0.1)
return tf.Variable(initial)

def bias_variable(shape):
initial = tf.constant(0.0, shape = shape)
return tf.Variable(initial)

def depthwise_conv2d(x, W):
return tf.nn.depthwise_conv2d(x,W, [1, 1, 1, 1], padding='VALID')

def apply_depthwise_conv(x,kernel_size,num_channels,depth):
weights = weight_variable([1, kernel_size, num_channels, depth])
biases = bias_variable([depth * num_channels])
return tf.nn.relu(tf.add(depthwise_conv2d(x, weights),biases))

def apply_max_pool(x,kernel_size,stride_size):
return tf.nn.max_pool(x, ksize=[1, 1, kernel_size, 1],
strides=[1, 1, stride_size, 1], padding='VALID')

X = tf.placeholder(tf.float32, shape=[None,input_height,input_width,num_channels],name="Mul")
Y = tf.placeholder(tf.float32, shape=[None,num_labels])

c = apply_depthwise_conv(X,kernel_size,num_channels,depth)
p = apply_max_pool(c,4,2)
c = apply_depthwise_conv(p,3,depth*num_channels,depth//6)

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//6), num_hidden]) #10
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))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

saver = tf.train.Saver()
with tf.Session() as session:
tf.global_variables_initializer().run()
for epoch in range(training_epochs):
cost_history = np.empty(shape=[1],dtype=float)
for b in range(total_batchs):
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}))
tf.train.write_graph(session.graph_def, '.', '../har.pbtxt')
saver.save(session,save_path = "../har.ckpt")


In the last line encounter this error message



ValueError: Cannot feed value of shape (10, 9) for Tensor 'Placeholder_2:0', which has shape '(?, 7)'



I tried changing some values but still I cannot fix this error.



What can I do to resolve this error?










share|improve this question






















  • Since you feed a (10 x 9) tensor into Y = tf.placeholder(tf.float32, shape=[None,num_labels]), which has shape (batch_size, 7). You need to check the length of Y should be 7 or 9.
    – HaoChien Hung
    Nov 18 at 11:20













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using Tensorflow to train my data for gesture recognition. Here is my Code:



import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
import tensorflow as tf

%matplotlib inline
plt.style.use('ggplot')

def read_data(file_path):
column_names = ['user-id','activity','timestamp','x-axis','y-axis','z-axis']
data = pd.read_csv(file_path,header = None, names = column_names, comment=';')
return data

def feature_normalize(dataset):
mu = np.mean(dataset,axis = 0)
sigma = np.std(dataset,axis = 0)
return (dataset - mu)/sigma

def plot_axis(ax, x, y, title):
ax.plot(x, y)
ax.set_title(title)
ax.xaxis.set_visible(False)
ax.set_ylim([min(y) - np.std(y), max(y) + np.std(y)])
ax.set_xlim([min(x), max(x)])
ax.grid(True)

def plot_activity(activity,data):
fig, (ax0, ax1, ax2) = plt.subplots(nrows = 3, figsize = (15, 10), sharex = True)
plot_axis(ax0, data['timestamp'], data['x-axis'], 'x-axis')
plot_axis(ax1, data['timestamp'], data['y-axis'], 'y-axis')
plot_axis(ax2, data['timestamp'], data['z-axis'], 'z-axis')
plt.subplots_adjust(hspace=0.2)
fig.suptitle(activity)
plt.subplots_adjust(top=0.90)
plt.show()

dataset = read_data('C:\Users\ASUS\Desktop\final_data.txt')
dataset['x-axis'] = feature_normalize(dataset['x-axis'])
dataset['y-axis'] = feature_normalize(dataset['y-axis'])
dataset['z-axis'] = feature_normalize(dataset['z-axis'])

for activity in np.unique(dataset["activity"]):
subset = dataset[dataset["activity"] == activity][:34]
plot_activity(activity,subset)

def windows(data, size):
start = 0
while start < data.count():
yield int(start), int(start + size)
start += (size / 2)

def segment_signal(data,window_size = 17):
segments = np.empty((0,window_size,3))
labels = np.empty((0))
for (start, end) in windows(data["timestamp"], window_size):
x = data["x-axis"][start:end]
y = data["y-axis"][start:end]
z = data["z-axis"][start:end]
if(len(dataset["timestamp"][start:end]) == window_size):
segments = np.vstack([segments,np.dstack([x,y,z])])
labels = np.append(labels,stats.mode(data["activity"][start:end])[0][0])
return segments, labels

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

train_test_split = np.random.rand(len(reshaped_segments)) < 0.80
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
input_width = 17
num_labels = 7
num_channels = 3

batch_size = 100
kernel_size = 5
depth = 60
num_hidden = 1000

learning_rate = 0.0001
training_epochs = 10

total_batchs = train_x.shape[0] // batch_size

def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev = 0.1)
return tf.Variable(initial)

def bias_variable(shape):
initial = tf.constant(0.0, shape = shape)
return tf.Variable(initial)

def depthwise_conv2d(x, W):
return tf.nn.depthwise_conv2d(x,W, [1, 1, 1, 1], padding='VALID')

def apply_depthwise_conv(x,kernel_size,num_channels,depth):
weights = weight_variable([1, kernel_size, num_channels, depth])
biases = bias_variable([depth * num_channels])
return tf.nn.relu(tf.add(depthwise_conv2d(x, weights),biases))

def apply_max_pool(x,kernel_size,stride_size):
return tf.nn.max_pool(x, ksize=[1, 1, kernel_size, 1],
strides=[1, 1, stride_size, 1], padding='VALID')

X = tf.placeholder(tf.float32, shape=[None,input_height,input_width,num_channels],name="Mul")
Y = tf.placeholder(tf.float32, shape=[None,num_labels])

c = apply_depthwise_conv(X,kernel_size,num_channels,depth)
p = apply_max_pool(c,4,2)
c = apply_depthwise_conv(p,3,depth*num_channels,depth//6)

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//6), num_hidden]) #10
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))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

saver = tf.train.Saver()
with tf.Session() as session:
tf.global_variables_initializer().run()
for epoch in range(training_epochs):
cost_history = np.empty(shape=[1],dtype=float)
for b in range(total_batchs):
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}))
tf.train.write_graph(session.graph_def, '.', '../har.pbtxt')
saver.save(session,save_path = "../har.ckpt")


In the last line encounter this error message



ValueError: Cannot feed value of shape (10, 9) for Tensor 'Placeholder_2:0', which has shape '(?, 7)'



I tried changing some values but still I cannot fix this error.



What can I do to resolve this error?










share|improve this question













I am using Tensorflow to train my data for gesture recognition. Here is my Code:



import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
import tensorflow as tf

%matplotlib inline
plt.style.use('ggplot')

def read_data(file_path):
column_names = ['user-id','activity','timestamp','x-axis','y-axis','z-axis']
data = pd.read_csv(file_path,header = None, names = column_names, comment=';')
return data

def feature_normalize(dataset):
mu = np.mean(dataset,axis = 0)
sigma = np.std(dataset,axis = 0)
return (dataset - mu)/sigma

def plot_axis(ax, x, y, title):
ax.plot(x, y)
ax.set_title(title)
ax.xaxis.set_visible(False)
ax.set_ylim([min(y) - np.std(y), max(y) + np.std(y)])
ax.set_xlim([min(x), max(x)])
ax.grid(True)

def plot_activity(activity,data):
fig, (ax0, ax1, ax2) = plt.subplots(nrows = 3, figsize = (15, 10), sharex = True)
plot_axis(ax0, data['timestamp'], data['x-axis'], 'x-axis')
plot_axis(ax1, data['timestamp'], data['y-axis'], 'y-axis')
plot_axis(ax2, data['timestamp'], data['z-axis'], 'z-axis')
plt.subplots_adjust(hspace=0.2)
fig.suptitle(activity)
plt.subplots_adjust(top=0.90)
plt.show()

dataset = read_data('C:\Users\ASUS\Desktop\final_data.txt')
dataset['x-axis'] = feature_normalize(dataset['x-axis'])
dataset['y-axis'] = feature_normalize(dataset['y-axis'])
dataset['z-axis'] = feature_normalize(dataset['z-axis'])

for activity in np.unique(dataset["activity"]):
subset = dataset[dataset["activity"] == activity][:34]
plot_activity(activity,subset)

def windows(data, size):
start = 0
while start < data.count():
yield int(start), int(start + size)
start += (size / 2)

def segment_signal(data,window_size = 17):
segments = np.empty((0,window_size,3))
labels = np.empty((0))
for (start, end) in windows(data["timestamp"], window_size):
x = data["x-axis"][start:end]
y = data["y-axis"][start:end]
z = data["z-axis"][start:end]
if(len(dataset["timestamp"][start:end]) == window_size):
segments = np.vstack([segments,np.dstack([x,y,z])])
labels = np.append(labels,stats.mode(data["activity"][start:end])[0][0])
return segments, labels

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

train_test_split = np.random.rand(len(reshaped_segments)) < 0.80
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
input_width = 17
num_labels = 7
num_channels = 3

batch_size = 100
kernel_size = 5
depth = 60
num_hidden = 1000

learning_rate = 0.0001
training_epochs = 10

total_batchs = train_x.shape[0] // batch_size

def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev = 0.1)
return tf.Variable(initial)

def bias_variable(shape):
initial = tf.constant(0.0, shape = shape)
return tf.Variable(initial)

def depthwise_conv2d(x, W):
return tf.nn.depthwise_conv2d(x,W, [1, 1, 1, 1], padding='VALID')

def apply_depthwise_conv(x,kernel_size,num_channels,depth):
weights = weight_variable([1, kernel_size, num_channels, depth])
biases = bias_variable([depth * num_channels])
return tf.nn.relu(tf.add(depthwise_conv2d(x, weights),biases))

def apply_max_pool(x,kernel_size,stride_size):
return tf.nn.max_pool(x, ksize=[1, 1, kernel_size, 1],
strides=[1, 1, stride_size, 1], padding='VALID')

X = tf.placeholder(tf.float32, shape=[None,input_height,input_width,num_channels],name="Mul")
Y = tf.placeholder(tf.float32, shape=[None,num_labels])

c = apply_depthwise_conv(X,kernel_size,num_channels,depth)
p = apply_max_pool(c,4,2)
c = apply_depthwise_conv(p,3,depth*num_channels,depth//6)

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//6), num_hidden]) #10
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))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

saver = tf.train.Saver()
with tf.Session() as session:
tf.global_variables_initializer().run()
for epoch in range(training_epochs):
cost_history = np.empty(shape=[1],dtype=float)
for b in range(total_batchs):
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}))
tf.train.write_graph(session.graph_def, '.', '../har.pbtxt')
saver.save(session,save_path = "../har.ckpt")


In the last line encounter this error message



ValueError: Cannot feed value of shape (10, 9) for Tensor 'Placeholder_2:0', which has shape '(?, 7)'



I tried changing some values but still I cannot fix this error.



What can I do to resolve this error?







python tensorflow machine-learning






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 at 6:45









Eugene Agustin

12




12












  • Since you feed a (10 x 9) tensor into Y = tf.placeholder(tf.float32, shape=[None,num_labels]), which has shape (batch_size, 7). You need to check the length of Y should be 7 or 9.
    – HaoChien Hung
    Nov 18 at 11:20


















  • Since you feed a (10 x 9) tensor into Y = tf.placeholder(tf.float32, shape=[None,num_labels]), which has shape (batch_size, 7). You need to check the length of Y should be 7 or 9.
    – HaoChien Hung
    Nov 18 at 11:20
















Since you feed a (10 x 9) tensor into Y = tf.placeholder(tf.float32, shape=[None,num_labels]), which has shape (batch_size, 7). You need to check the length of Y should be 7 or 9.
– HaoChien Hung
Nov 18 at 11:20




Since you feed a (10 x 9) tensor into Y = tf.placeholder(tf.float32, shape=[None,num_labels]), which has shape (batch_size, 7). You need to check the length of Y should be 7 or 9.
– HaoChien Hung
Nov 18 at 11:20

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358537%2ftensorflow-cannot-feed-value-of-shape-10-9-for-tensor-placeholder-20-whic%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358537%2ftensorflow-cannot-feed-value-of-shape-10-9-for-tensor-placeholder-20-whic%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno