chiphuyen / stanford-tensorflow-tutorials

This repository contains code examples for the Stanford's course: TensorFlow for Deep Learning Research.
http://cs20.stanford.edu
MIT License
10.32k stars 4.32k forks source link

Error in HuberLoss #93

Open vkgpt11 opened 6 years ago

vkgpt11 commented 6 years ago

def huber_loss(labels, predictions, delta=1.0): residual = tf.abs(labels - predictions) def f1(): return 0.5 tf.square(residual) def f2(): return delta residual - 0.5 * tf.square(delta) return tf.cond(residual < delta, f1, f2)

Step 4: predict Y (number of theft) from the number of fire

Y_predicted = w X X + X * u + b

Step 5: Profit!

loss = huber_loss(Y, Y_predicted)

optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001).minimize(loss)

I am getting Error "Shape must be rank 0 but is rank 1 for 'cond_4/Switch' (op: 'Switch') with input shapes: [190], [190]." on step no 5

chiphuyen commented 6 years ago

I don't see anything immediately wrong with the portion of the code you posted.

dtczhl commented 6 years ago

I came across similar error. My fault was that I created 1-D array instead of scalar

Error code w = tf.get_variable('w', shape=(1, 1), initializer=tf.constant_initializer(0.0)) which should be w = tf.get_variable('w', shape=[], initializer=tf.constant_initializer(0.0))