找到解决办法了。
卸载最新版本的tensorflow并恢复到以前的模型
# Uninstall the current version of TensorFlow.
!pip uninstall tensorflow -2.13.0
# Install TensorFlow 1.15.0.
!pip install tensorflow==2.12.0
# Verify the TensorFlow version.
import tensorflow as tf
print(tf.__version__)
字符串
使用Google Colab。这是我运行model.fit(x,y)时的错误。
AttributeError:模块'tensorflow.python.distribute.input_lib'没有属性'DistributedDatasetInterface'
我读到它涉及到'keras'和'tensorflow'之间的兼容性问题,解决的方法是在谷歌colab中更新tensor flow,
!pip install -U tensorflow
型
我这样做了,我的tensorflow版本现在是2.13.0,但这并没有解决这个问题。
这些是我的图书馆
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import PolynomialFeatures
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dense
from tensorflow.python.keras.activations import linear
from tensorflow.python.keras.optimizers import adam_v2
型
序列
1.加载csv文件,提取数据并重新整形。
1.使用sklearn train_test_split()创建训练、验证和测试集
1.使用**tf.keras.layers.Normalization(axis=-1,mean=None,variance=None)**对所有x_train,x_validation,x_test数据进行归一化
1.运行模型
[
tf.keras.layers.Dense(input_shape=(30,), units=15, activation='relu',
name='L1'),
tf.keras.layers.Dense(input_shape=(15,), units=10, activation='relu',
name='L2'),
tf.keras.layers.Dense(input_shape=(10,), units=1, activation='linear',
name='L3'),
] , name="My_Model"
)
opt = adam_v2.Adam(learning_rate=0.001)
loss = tf.keras.losses.MeanSquaredError()
model.compile(
loss = loss,
optimizer = opt,
)
model.fit(xn_train, y_train, epochs=100)
型
这是有错误的**model.fit()**部分。
a.所以我确保输入(xn_train,y_train)都是<class 'numpy. ndarray'>。
B.然后确保,但输入都是<class 'tensorflow.python.framework.ops. penserTensor'>。这也没有修复它
请帮助解决这个问题。
1条答案
按热度按时间stszievb1#
tensorflow/python/keras是遗留代码。请删除它并使用tf.keras。
下面的例子对我来说很有用。
字符串
或
型