Керас слои не имеет атрибута Плотный - PullRequest
0 голосов
/ 06 мая 2019

В настоящее время я участвую в курсе Coursera-Введение в TensorFlow для искусственного интеллекта, машинного обучения и глубокого обучения.Я получил ошибку в следующем коде.

Вот мой код Python,

# y = 2x - 1

import tensorflow as tf
# helps us to represent our data as lists easily and quickly
import numpy as np
# framework for defining a neural network as a set of Sequential layers
from tensorflow import keras

# The LOSS function measures the guessed answers against the known correct 
# answers and measures how well or how badly it did
# then uses the OPTIMIZER function to make another guess. Based on how the 
# loss function went, it will try to minimize the loss.

model = tf.keras.Sequential([keras.layers.Dence(units=1, input_shape= 
[1])])
model.compile(optimizer='sgd', loss='mean_squared_error')

# providing data
xs = np.array([-1.0,0.0,1.0,2.0,3.0,4.0],dtype=float)
ys = np.array([-3.0,-1.0,1.0,3.0,5.0,7.0],dtype=float)

# training neural network
model.fit(xs,ys,epochs=500)

# figure out value for unknown x
print(model.predict([10.0]))

Я получил это сообщение об ошибке в терминале.

C:\anaconda\envs\tfp\pythonw.exe C:/Users/USER/PycharmProjects/couseraTensorflow/helloWorld.py
Traceback (most recent call last):
  File "C:/Users/USER/PycharmProjects/couseraTensorflow/helloWorld.py", line 11, in <module>
    model = tf.keras.Sequential([keras.layers.Dence(units=1, input_shape=[1])])
AttributeError: module 'tensorflow._api.v1.keras.layers' has no attribute 'Dence'

Process finished with exit code 1

Ответы [ 2 ]

0 голосов
/ 06 мая 2019

Имя слоя: Den s e, а не Den c e.

0 голосов
/ 06 мая 2019

попробуйте это в TF 2.0.0-alpha0

import tensorflow as tf
# helps us to represent our data as lists easily and quickly
import numpy as np
# framework for defining a neural network as a set of Sequential layers
from tensorflow import keras

# The LOSS function measures the guessed answers against the known correct 
# answers and measures how well or how badly it did
# then uses the OPTIMIZER function to make another guess. Based on how the 
# loss function went, it will try to minimize the loss.

model = tf.keras.models.Sequential([keras.layers.Dense(units=1, input_shape= 
[1])])
model.compile(optimizer='sgd', loss='mean_squared_error')

# providing data
xs = np.array([-1.0,0.0,1.0,2.0,3.0,4.0],dtype=float)
ys = np.array([-3.0,-1.0,1.0,3.0,5.0,7.0],dtype=float)

# training neural network
model.fit(xs,ys,epochs=500)

# figure out value for unknown x
print(model.predict([10.0]))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...