简体   繁体   中英

Keras Stuck on First Epoch

I was trying to test out whether Keras and TensorFlow are working on my MacBook Pro on the latest Mojave with 32GB of RAM and apparently it is not!

I tried installing them in a separate, new environment, and it worked fine, but I don't understand why it won't work in my base (root) environment.

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)

I expected to get this result, which I did in my clean environment:

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>

But instead, I only got this:

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

I ran the exact same code on the exact same computer using the exact same installation method (pip).

Any and all help would be greatly appreciated!

Couldn't replicate the error, I used python 3.6.7 and 3.7.3 in manjaro. To download the packages I used:

conda install -c conda-forge jupyterlab scikit-learn keras

Can you tell me how you installed the libraries? Otherwise you can try using the command above to install the libraries.

If it doesn't work could be something else.

So, the problem was pip install... I uninstalled everything and installed it through conda-forge and it finally worked. Hope it helps those who run into this issue in the future!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM