【问题标题】:FailedPreconditionError Tensorflow TrainFailedPreconditionError Tensorflow 训练
【发布时间】:2020-08-05 07:16:11
【问题描述】:

我正在测试在 Google Colab 中为图像着色的代码。

from keras.models import Model, Sequential, load_model
from keras.layers.merge import concatenate
from keras.layers.pooling import MaxPooling2D
from keras.preprocessing.image import ImageDataGenerator
from keras.layers.convolutional import Conv2D, Conv2DTranspose
from keras.layers import Input, UpSampling2D, RepeatVector, Reshape
from keras.callbacks import EarlyStopping, ModelCheckpoint, ReduceLROnPlateau
from keras.applications.inception_resnet_v2 import InceptionResNetV2, preprocess_input
from keras import backend as K

import tensorflow as tf
print(tf.__version__)

Using TensorFlow backend.
1.14.0

我使用的是tensorflow 1.14.0,因为原始代码来自Kaggle,原文:https://www.kaggle.com/valkling/image-colorization-using-autoencoders-and-resnet/notebook

在训练之前,任何单元都没有问题。当执行此代码时,它会失败。

%%time
BATCH_SIZE = 20
model.fit_generator(
    image_a_b_gen(X_train, BATCH_SIZE),
    epochs=30,
    verbose=1,
    steps_per_epoch=X_train.shape[0]/BATCH_SIZE,
    callbacks=model_callbacks)

错误是:

Epoch 1/30

---------------------------------------------------------------------------
FailedPreconditionError                   Traceback (most recent call last)

<ipython-input-14-61e8a51cf536> in <module>()
----> 1 get_ipython().run_cell_magic('time', '', 'BATCH_SIZE = 20\nmodel.fit_generator(\n    image_a_b_gen(X_train, BATCH_SIZE),\n    epochs=30,\n    verbose=1,\n    steps_per_epoch=X_train.shape[0]/BATCH_SIZE,\n    callbacks=model_callbacks)')

<decorator-gen-60> in time(self, line, cell, local_ns)

<timed exec> in <module>()

<timed exec> in image_a_b_gen(dataset, batch_size)

<timed exec> in create_inception_embedding(grayscaled_rgb)

1456         ret = tf_session.TF_SessionRunCallable(self._session._session,
   1457                                                self._handle, args,
-> 1458                                                run_metadata_ptr)
   1459         if run_metadata:
   1460           proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

FailedPreconditionError: Error while reading resource variable conv2d_45/kernel from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/conv2d_45/kernel)
     [[{{node conv2d_45/convolution/ReadVariableOp}}]]

我认为可能与tensorflow或sessions的版本有关,但我找不到任何解决办法。

谢谢

【问题讨论】:

    标签: python tensorflow keras deep-learning google-colaboratory


    【解决方案1】:

    我如何认为解决方案非常简单并且与版本问题有关。

    kaggle中keras和tensorflow的版本分别是2.2.4和1.14.0。使用以下说明更改 Google Colab 版本的解决方案很简单:

    !pip install tensorflow==1.14.0
    !pip install keras==2.2.4
    

    然后重启de Notebook就完成了。

    【讨论】:

      猜你喜欢
      • 2016-03-09
      • 1970-01-01
      • 2017-03-30
      • 2017-08-21
      • 2018-05-22
      • 2018-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多