My first AI doesent work.

138 views
Skip to first unread message

tauking

unread,
Jul 29, 2020, 5:35:04 AM7/29/20
to TensorFlow Hub

19:26
I am trying to create an AI with tensorflow.
19:26
import tensorflow as tf from tensorflow import keras model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])]) model.compile(optimizer='sgd', loss='mean_square_error') xs=[1, 2, 3] ys=[2, 4, 6] model.fit(xs, ys, epochs=1000) print(model.predict([7]))
19:26
But I get this error!
Please help me.



Epoch 1/1000 --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-2-8309fc54a25a> in <module>() 8 ys=[2, 4, 6] 9 ---> 10 model.fit(xs, ys, epochs=1000) 11 12 print(model.predict([7])) 10 frames /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs) 966 except Exception as e: # pylint:disable=broad-except 967 if hasattr(e, "ag_error_metadata"): --> 968 raise e.ag_error_metadata.to_exception(e) 969 else: 970 raise ValueError: in user code: /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:571 train_function * outputs = self.distribute_strategy.run( /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:951 run ** return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs) /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2290 call_for_each_replica return self._call_for_each_replica(fn, args, kwargs) /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2649 _call_for_each_replica return fn(*args, **kwargs) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:533 train_step ** y, y_pred, sample_weight, regularization_losses=self.losses) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:187 __call__ self._build(y_pred) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:140 _build self._losses = nest.map_structure(self._get_loss_object, self._losses) /usr/local/lib/python3.6/dist-packages/tensorflow/python/util/nest.py:617 map_structure structure[0], [func(*x) for x in entries], /usr/local/lib/python3.6/dist-packages/tensorflow/python/util/nest.py:617 <listcomp> structure[0], [func(*x) for x in entries], /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:264 _get_loss_object loss = losses_mod.get(loss) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/losses.py:1857 get return deserialize(identifier) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/losses.py:1835 deserialize printable_module_name='loss function') /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/generic_utils.py:392 deserialize_keras_object raise ValueError('Unknown ' + printable_module_name + ':' + object_name) ValueError: Unknown loss function:mean_square_error

Sambit Mahapatra

unread,
Jul 29, 2020, 5:49:13 AM7/29/20
to TensorFlow Hub
https://www.tensorflow.org/api_docs/python/tf/keras/losses/MeanSquaredError
tf.keras.losses.MeanSquaredError(reduction=losses_utils.ReductionV2.AUTO, name='mean_squared_error')

So, you can either use 'mean_squared_error' or tf.keras.losses.MeanSquaredError() in loss function at model.compile()

Daniel Roy

unread,
Jul 29, 2020, 5:38:12 PM7/29/20
to Sambit Mahapatra, TensorFlow Hub
first email I ever received from the list and that sounds like a joke

--
You received this message because you are subscribed to the Google Groups "TensorFlow Hub" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hub+uns...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/hub/e32b585b-fb9f-4413-9602-909de6e5133ao%40tensorflow.org.

Sambit Mahapatra

unread,
Jul 30, 2020, 2:27:55 AM7/30/20
to TensorFlow Hub, daniel.r...@gmail.com, Sambit Mahapatra
you didn't like the answer :)

Daniel Roy

unread,
Jul 30, 2020, 6:29:59 PM7/30/20
to Sambit Mahapatra, TensorFlow Hub
your answer is actually excellent!
Reply all
Reply to author
Forward
0 new messages