【发布时间】:2021-07-16 08:57:13
【问题描述】:
我正在使用 macbook pro m1,发现无法将 tensorflow 与 Anaconda 一起使用,因此我通过以下链接逐步安装它: https://towardsdatascience.com/installing-tensorflow-on-the-m1-mac-410bb36b776
我现在可以导入 tensorflow 并使用以下链接中的代码进行测试,但遇到了问题。 https://machinelearningmastery.com/neural-network-for-cancer-survival-dataset/
它在 colab 上成功运行,但在我的 macbook 上却没有。
代码如下:
# fit a simple mlp model on the haberman and review learning curves
from pandas import read_csv
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import accuracy_score
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense
from matplotlib import pyplot
# load the dataset
path = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/haberman.csv'
df = read_csv(path, header=None)
# split into input and output columns
X, y = df.values[:, :-1], df.values[:, -1]
# ensure all data are floating point values
X = X.astype('float32')
# encode strings to integer
y = LabelEncoder().fit_transform(y)
# split into train and test datasets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, stratify=y, random_state=3)
# determine the number of input features
n_features = X.shape[1]
# define model
model = Sequential()
model.add(Dense(10, activation='relu', kernel_initializer='he_normal', input_shape=(n_features,)))
model.add(Dense(1, activation='sigmoid'))
# compile the model
model.compile(optimizer='adam', loss='binary_crossentropy')
# fit the model
history = model.fit(X_train, y_train, epochs=200, batch_size=16, verbose=0, validation_data=(X_test,y_test))
当我运行这个时:
# predict test set
yhat = model.predict_classes(X_test)
内核死了。
我已经尝试删除 miniforge3 文件夹并重新安装 tensorflow,但问题仍然存在。
版本:
Python 3.8.10
张量流 2.4.0-rc0
有一些 WARNING 来了,但我认为这不重要,如果可能,请让我在这里发布。
【问题讨论】:
-
你能把标题改成你要问的吗?
标签: python tensorflow apple-m1