Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16624

"unexpected indent" or "object has no attribute 'compile'" errors [duplicate]

$
0
0

I tried using this code from the Tensorflow basic regression tutorial:

def build_model():  model = keras.Sequential([    keras.layers.Dense(64, activation=tf.nn.relu,                        input_shape=(train_data.shape[1],)),    keras.layers.Dense(64, activation=tf.nn.relu),    keras.layers.Dense(1)  ])  optimizer = tf.train.RMSPropOptimizer(0.001)  model.compile(loss='mse',                optimizer=optimizer,                metrics=['mae'])  return modelmodel = build_model()model.summary()

But I get an error that says:

>>>   optimizer = tf.train.RMSPropOptimizer(0.001)  File "<stdin>", line 1    optimizer = tf.train.RMSPropOptimizer(0.001)    ^IndentationError: unexpected indent

If I unindent the optimizer = ... line, the next line gives the same error. If I then unindent the model.compile ... line, I get this:

>>> model.compile(loss='mse',...                 optimizer=optimizer,...                 metrics=['mae'])Traceback (most recent call last):  File "<stdin>", line 1, in <module>AttributeError: 'NoneType' object has no attribute 'compile'

...followed by a bunch of other errors, probably resulting from that one.

The other tutorials have worked fine. What is wrong, and how do I fix it?


Viewing all articles
Browse latest Browse all 16624

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>