如何配置支持 CPU 的 tensorflow?

How to configure tensorflow with CPU support?

我正在尝试 运行 tensorflow CPU 支持。

张量流:
版本:1.14.0

凯拉斯:
版本:2.3.1

当我尝试 运行 以下代码时:

def run_test_harness(trainX,trainY,testX,testY):
    datagen=ImageDataGenerator(rescale=1.0/255.0)
    train_it = datagen.flow(trainX, trainY, batch_size=1)
    test_it = datagen.flow(testX, testY, batch_size=1)
    model=define_model()

    history = model.fit_generator(train_it, steps_per_epoch=len(train_it),
        validation_data=test_it, validation_steps=len(test_it), epochs=1, verbose=0)

我收到以下错误,如图所示:

Image shows the error

我尝试为相同的配置 bazel,但没有用。如果有人可以指导我获取资源或帮助解决问题,那将会很有帮助。谢谢

编辑:(警告信息)

WARNING:tensorflow:From /home/neha/valiance/kerascpu/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:4070: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.

WARNING:tensorflow:From /home/neha/valiance/kerascpu/lib/python3.6/site-packages/tensorflow/python/ops/nn_impl.py:180: add_dispatch_support.<locals>.wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
2020-10-22 12:41:36.023849: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-10-22 12:41:36.326420: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2299965000 Hz
2020-10-22 12:41:36.327496: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5502350 executing computations on platform Host. Devices:
2020-10-22 12:41:36.327602: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
2020-10-22 12:41:36.679930: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set.  If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU.  To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.
2020-10-22 12:41:36.890241: W tensorflow/core/framework/allocator.cc:107] Allocation of 3406823424 exceeds 10% of system memory.
^Z
[1]+  Stopped                 python3 model.py

您应该尝试 运行在 google colab 上使用您的代码。我认为您的 PC 上没有足够的可用资源来完成您尝试 运行 的任务,即使您使用的 batch_size 为 1.