Tensorflow custom loss feed

Viewed 844

I want to feed calculated loss ( which is self.calc_loss/d_reward_sum and its value is 1.0288568 ) to self.sess.run(tf.compat.v1.train.AdamOptimizer().minimize(d_reward_sum)) then it shows error

AttributeError: 'numpy.dtype' object has no attribute 'base_dtype'

If i use placeholder

self.calc_loss = tf.placeholder(tf.float32) 
self.train_opt = tf.compat.v1.train.AdamOptimizer().minimize(self.calc_loss)
...   
train_modal = self.sess.run([self.train_opt],feed_dict = {
            self.calc_loss :d_reward_sum ,
        })

then it give error

> ([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 ["<tf.Variable 'Variable:0'
> shape=(4, 24) dtype=float32_ref>", "<tf.Variable 'Variable_1:0'
> shape=(24,) dtype=float32_ref>", "<tf.Variable 'Variable_2:0'
> shape=(24, 12) dtype=float32_ref>", "<tf.Variable 'Variable_3:0'
> shape=(12,) dtype=float32_ref>", "<tf.Variable 'Variable_4:0'
> shape=(12, 4) dtype=float32_ref>", "<tf.Variable 'Variable_5:0'
> shape=(4,) dtype=float32_ref>", "<tf.Variable 'Variable_6:0' shape=(4,
> 2) dtype=float32_ref>"] and loss Tensor("Placeholder:0",
> dtype=float32).

If i do

self.sess.run(tf.compat.v1.train.AdamOptimizer().minimize(tf.constant(4.1, tf.float32, name='A')))

Then also error is same as above

What value it is expecting ?

0 Answers
Related