Keras 停留在第一个纪元
Keras Stuck on First Epoch
我试图测试 Keras 和 TensorFlow 是否可以在我的 MacBook Pro 上运行,我的 MacBook Pro 配备了最新的 Mojave 和 32GB 内存,但显然不行!
我尝试将它们安装在一个单独的新环境中,并且运行良好,但我不明白为什么它不能在我的基本(根)环境中运行。
from keras.models import Sequential
from keras.layers import Dense
from keras.utils import to_categorical
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=1000, n_features=20)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
ss = StandardScaler()
X_train_sc = ss.fit_transform(X_train)
X_test_sc = ss.transform(X_test)
model = Sequential()
model.add(Dense(32, input_dim=20, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(X_train_sc, y_train, validation_data=(X_test_sc, y_test), epochs=10, batch_size=32)
我希望得到这个结果,这是我在干净的环境中做的:
WARNING:tensorflow:From /Users/Hovanes/anaconda3/envs/clean/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
Train on 750 samples, validate on 250 samples
Epoch 1/10
2019-04-26 19:04:32.220021: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
750/750 [==============================] - 0s 235us/step - loss: 30460.2991 - val_loss: 30451.6543
Epoch 2/10
750/750 [==============================] - 0s 23us/step - loss: 30384.4905 - val_loss: 30375.6350
Epoch 3/10
750/750 [==============================] - 0s 22us/step - loss: 30292.1559 - val_loss: 30280.5673
Epoch 4/10
750/750 [==============================] - 0s 23us/step - loss: 30162.1524 - val_loss: 30141.1293
Epoch 5/10
750/750 [==============================] - 0s 22us/step - loss: 29971.8937 - val_loss: 29918.3467
Epoch 6/10
750/750 [==============================] - 0s 23us/step - loss: 29689.4520 - val_loss: 29591.1545
Epoch 7/10
750/750 [==============================] - 0s 22us/step - loss: 29266.3404 - val_loss: 29122.6358
Epoch 8/10
750/750 [==============================] - 0s 22us/step - loss: 28671.3374 - val_loss: 28470.9937
Epoch 9/10
750/750 [==============================] - 0s 23us/step - loss: 27898.4042 - val_loss: 27585.4375
Epoch 10/10
750/750 [==============================] - 0s 22us/step - loss: 26869.9945 - val_loss: 26530.5343
<keras.callbacks.History object at 0x136d07630>
但是,我只得到了这个:
WARNING:tensorflow:From /Users/Hovanes/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
Train on 750 samples, validate on 250 samples
Epoch 1/10
我 运行 在完全相同的计算机上使用完全相同的安装方法 (pip) 使用完全相同的代码。
任何帮助将不胜感激!
无法重现错误,我在 manjaro 中使用了 python 3.6.7 和 3.7.3。
要下载我使用的软件包:
conda 安装-c conda-forge jupyterlab scikit-learn keras
你能告诉我你是如何安装库的吗?否则你可以尝试使用上面的命令来安装库。
如果它不起作用可能是其他原因。
所以,问题是 pip install...我卸载了所有东西并通过 conda-forge 安装它,它终于成功了。希望对以后运行遇到这个问题的人有所帮助!
我试图测试 Keras 和 TensorFlow 是否可以在我的 MacBook Pro 上运行,我的 MacBook Pro 配备了最新的 Mojave 和 32GB 内存,但显然不行!
我尝试将它们安装在一个单独的新环境中,并且运行良好,但我不明白为什么它不能在我的基本(根)环境中运行。
from keras.models import Sequential
from keras.layers import Dense
from keras.utils import to_categorical
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=1000, n_features=20)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
ss = StandardScaler()
X_train_sc = ss.fit_transform(X_train)
X_test_sc = ss.transform(X_test)
model = Sequential()
model.add(Dense(32, input_dim=20, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(X_train_sc, y_train, validation_data=(X_test_sc, y_test), epochs=10, batch_size=32)
我希望得到这个结果,这是我在干净的环境中做的:
WARNING:tensorflow:From /Users/Hovanes/anaconda3/envs/clean/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
Train on 750 samples, validate on 250 samples
Epoch 1/10
2019-04-26 19:04:32.220021: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
750/750 [==============================] - 0s 235us/step - loss: 30460.2991 - val_loss: 30451.6543
Epoch 2/10
750/750 [==============================] - 0s 23us/step - loss: 30384.4905 - val_loss: 30375.6350
Epoch 3/10
750/750 [==============================] - 0s 22us/step - loss: 30292.1559 - val_loss: 30280.5673
Epoch 4/10
750/750 [==============================] - 0s 23us/step - loss: 30162.1524 - val_loss: 30141.1293
Epoch 5/10
750/750 [==============================] - 0s 22us/step - loss: 29971.8937 - val_loss: 29918.3467
Epoch 6/10
750/750 [==============================] - 0s 23us/step - loss: 29689.4520 - val_loss: 29591.1545
Epoch 7/10
750/750 [==============================] - 0s 22us/step - loss: 29266.3404 - val_loss: 29122.6358
Epoch 8/10
750/750 [==============================] - 0s 22us/step - loss: 28671.3374 - val_loss: 28470.9937
Epoch 9/10
750/750 [==============================] - 0s 23us/step - loss: 27898.4042 - val_loss: 27585.4375
Epoch 10/10
750/750 [==============================] - 0s 22us/step - loss: 26869.9945 - val_loss: 26530.5343
<keras.callbacks.History object at 0x136d07630>
但是,我只得到了这个:
WARNING:tensorflow:From /Users/Hovanes/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
Train on 750 samples, validate on 250 samples
Epoch 1/10
我 运行 在完全相同的计算机上使用完全相同的安装方法 (pip) 使用完全相同的代码。
任何帮助将不胜感激!
无法重现错误,我在 manjaro 中使用了 python 3.6.7 和 3.7.3。 要下载我使用的软件包:
conda 安装-c conda-forge jupyterlab scikit-learn keras
你能告诉我你是如何安装库的吗?否则你可以尝试使用上面的命令来安装库。
如果它不起作用可能是其他原因。
所以,问题是 pip install...我卸载了所有东西并通过 conda-forge 安装它,它终于成功了。希望对以后运行遇到这个问题的人有所帮助!