前提・実現したいこと
Face Sketch to Image Generation using GANの実装を行う際に以下のエラーが発生しました
発生している問題・エラーメッセージ
AttributeError Traceback (most recent call last) <ipython-input-37-087d48d24ecb> in <module> 1 img_shape = (256, 256, 3) 2 ----> 3 d_model = discriminator(img_shape) 4 5 g_model = generator(img_shape) 7 frames <ipython-input-32-8e022b387e74> in discriminator(img_shape) 13 14 d1 = d_layer(merged, 64, norm=False) ---> 15 d2 = d_layer(d1, 128) 16 d3 = d_layer(d1, 256) 17 d4 = d_layer(d1, 512) <ipython-input-32-8e022b387e74> in d_layer(layer_in, n_filter, norm) 4 d = LeakyReLU(0.2)(d) 5 if norm: ----> 6 d = InstanceNormalization()(d) 7 return d 8 /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs) 661 kwargs.pop('training') 662 inputs, outputs = self._set_connectivity_metadata_( --> 663 inputs, outputs, args, kwargs) 664 self._handle_activity_regularization(inputs, outputs) 665 self._set_mask_metadata(inputs, outputs, previous_mask) /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/base_layer.py in _set_connectivity_metadata_(self, inputs, outputs, args, kwargs) 1706 kwargs.pop('mask', None) # `mask` should not be serialized. 1707 self._add_inbound_node( -> 1708 input_tensors=inputs, output_tensors=outputs, arguments=kwargs) 1709 return inputs, outputs 1710 /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/base_layer.py in _add_inbound_node(self, input_tensors, output_tensors, arguments) 1793 """ 1794 inbound_layers = nest.map_structure(lambda t: t._keras_history.layer, -> 1795 input_tensors) 1796 node_indices = nest.map_structure(lambda t: t._keras_history.node_index, 1797 input_tensors) /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/nest.py in map_structure(func, *structure, **kwargs) 513 514 return pack_sequence_as( --> 515 structure[0], [func(*x) for x in entries], 516 expand_composites=expand_composites) 517 /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/nest.py in <listcomp>(.0) 513 514 return pack_sequence_as( --> 515 structure[0], [func(*x) for x in entries], 516 expand_composites=expand_composites) 517 /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/base_layer.py in <lambda>(t) 1792 `call` method of the layer at the call that created the node. 1793 """ -> 1794 inbound_layers = nest.map_structure(lambda t: t._keras_history.layer, 1795 input_tensors) 1796 node_indices = nest.map_structure(lambda t: t._keras_history.node_index, AttributeError: 'tuple' object has no attribute 'layer'
該当のソースコード
img_shape = (256, 256, 3) d_model = discriminator(img_shape) g_model = generator(img_shape) gan_model = GAN(g_model, d_model, img_shape)
d_model = discriminator(img_shape)←ここでエラー発生
試したこと
1.jupyter notebookで実行→AttributeError
2.google colabで実行→実行成功
3.一定時間操作なしで切断されたので、再度実行→jupyter notebookで実行したときと全く同じエラーが発生
google colabで実行して、一回目は実行できたのに二回目全く同じエラーが発生する原因が分かりません(もちろんGPU使用量上限に達したわけではなく、ソースコードもいじってない)
このエラーの原因について教えてください
補足情報(FW/ツールのバージョンなど)
また、下記のインポート文を実行すると
from __future__ import print_function, division from keras_contrib.layers.normalization.instancenormalization import InstanceNormalization from keras.layers import Input, Dense, Reshape, Flatten, Dropout, Concatenate, BatchNormalization, Activation, ZeroPadding2D from keras.layers.advanced_activations import LeakyReLU from keras.layers.convolutional import UpSampling2D, Conv2D from keras.models import Sequential, Model from keras.optimizers import Adam from keras.preprocessing.image import img_to_array from keras.preprocessing.image import load_img from sklearn.utils import shuffle import matplotlib.pyplot as plt import numpy as np import datetime import natsort import scipy import sys import os import cv2
実行結果↓
WARNING:tensorflow:From /content/drive/My Drive/Colab Notebooks/senga-Face-Sketch-to-Image-Generation-using-GAN-master/keras-contrib/keras_contrib/layers/advanced_activations/srelu.py:43: The name tf.keras.initializers.RandomUniform is deprecated. Please use tf.compat.v1.keras.initializers.RandomUniform instead. WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/initializers.py:119: calling RandomUniform.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version. Instructions for updating: Call initializer instance with the dtype argument instead of passing it to the constructor
このような警告文が発生することがあります(これが出ると確定でAttributeErrorが発生し、出ないと実行が成功する)
回答1件
あなたの回答
tips
プレビュー