【发布时间】: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