【发布时间】:2020-04-21 21:20:33
【问题描述】:
我根据these 说明使用 conda 在我的 mac 上安装了 tensorflow 2:
conda create -n tf2 tensorflow
然后我安装了 ipykernel 以将这个新环境添加到我的 jupyter notebook 内核中,如下所示:
conda activate tf2
conda install ipykernel
python -m ipykernel install --user --name=tf2
这似乎运作良好,我可以在我的 jupyter notebook 内核上看到我的 tf2 环境。
然后我尝试运行简单的 MNIST example 来检查是否一切正常,当我执行这行代码时:
model.fit(x_train, y_train, epochs=5)
我的 jupyter notebook 的内核在没有更多信息的情况下死掉了。
我通过 python mnist_test.py 和 ipython(通过命令命令)在我的终端上执行了相同的代码,我没有任何问题,让我们我假设我的 tensorflow 2 已正确安装在我的 conda 环境中。
关于安装过程中出了什么问题有什么想法吗?
版本:
python==3.7.5
tensorboard==2.0.0
tensorflow==2.0.0
tensorflow-estimator==2.0.0
ipykernel==5.1.3
ipython==7.10.2
jupyter==1.0.0
jupyter-client==5.3.4
jupyter-console==5.2.0
jupyter-core==4.6.1
这里我放了完整的脚本以及执行的STDOUT:
import tensorflow as tf
import matplotlib.pyplot as plt
import seaborn as sns
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
nn_model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation='softmax')
])
nn_model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
nn_model.fit(x_train, y_train, epochs=5)
nn_model.evaluate(x_test, y_test, verbose=2)
(tf2) ➜ tensorflow2 python mnist_test.py 2020-01-03 10:46:10.854619: 我 tensorflow/core/platform/cpu_feature_guard.cc:145] 这个 TensorFlow 使用 Intel(R) MKL-DNN 优化二进制文件以使用以下 CPU 性能关键操作中的指令:SSE4.1 SSE4.2 AVX AVX2 FMA 要在非 MKL-DNN 操作中启用它们,请重建 TensorFlow 使用适当的编译器标志。 2020-01-03 10:46:10.854860: 我 tensorflow/core/common_runtime/process_util.cc:115] 创建新的 具有默认互操作设置的线程池:8. 调整使用 inter_op_parallelism_threads 以获得最佳性能。训练60000 样本 Epoch 1/5 60000/60000 [===============================] - 6s 102us/样本 - 损失:0.3018 - 准确度:0.9140 Epoch 2/5 60000/60000 [==============================] - 6s 103us/样本 - 损失:0.1437 - 精度:0.9571 Epoch 3/5 60000/60000 [==============================] - 6s 103us/样本 - 损失:0.1054 - 精度:0.9679 纪元 4/5 60000/60000 [==============================] - 6s 103us/样本 - 损失:0.0868 - 精度:0.9729 Epoch 5/5 60000/60000 [===============================] - 6s 103us/样本 - 损失:0.0739 - 精度:0.9772 10000/1 - 1s - 损耗:0.0359 - 精度:0.9782 (tf2) ➜张量流2
【问题讨论】:
-
你试过检查你的机器有多少内存被使用了吗?可能是因为内存不足而死。
-
@YOLO 就在调用 nn_model.fit(..) 行之前,它使用了 180MB 的 RAM,然后就死掉了。我的 Mac 有 16GB 的 RAM,所以我不认为它来自那里......
标签: python tensorflow jupyter-notebook conda