1

System information
- Windows 10
- TensorFlow backend (yes / no): yes
- TensorFlow version: 1.14.0
- Keras version: 2.24
- Python version: 3.6
- CUDA/cuDNN version: 10
- GPU model and memory: gtx 1050 ti

Describe the current behavior
I installed tensoflow and keras via conda. Then i tried to run this code:

import tensorflow as tf
import keras
import numpy as np

model = keras.Sequential([keras.layers(units=1, input_shape=[1])])

model.compile(optimizer="sgd", loss="mean_squared_error")

x = np.array([-1, 0, 1, 2, 3, 4])
y = np.array([-3, -1, 1, 3, 5, 7])

model.fit(x, y, epochs=500)

print(model.predict([10]))`

When i run this code I get the error:

Using TensorFlow backend.
Traceback (most recent call last):
  File "C:/Users/xxx/PycharmProjects/Workspace/tensorflow/hello_world_of_nn.py", line 5, in <module>
    model = keras.Sequential([keras.layers(units=1, input_shape=[1])])
TypeError: 'module' object is not callable

When i try this:
python -c 'import keras as k; print(k.__version__)'

I get the error:

C:\Users\xxx>python -c 'import keras as k; print(k.__version__)'
  File "<string>", line 1
    'import
          ^
SyntaxError: EOL while scanning string literal

1 Answer 1

3

This should be fine:

import tensorflow as tf
import keras
import numpy as np

model = keras.models.Sequential([keras.layers.Dense(units=1, input_shape=[1])])

model.compile(optimizer="sgd", loss="mean_squared_error")

x = np.array([-1, 0, 1, 2, 3, 4])
y = np.array([-3, -1, 1, 3, 5, 7])

model.fit(x, y, epochs=500)

print(model.predict([10]))

Please note the usage of keras.models.Sequential and keras.layers.Dense.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.