Issue
The code works well in tensorflow==1.14 and keras==2.2.4 :
def data_generator(images, descriptions, VGG16) :
while True :
for i in range(0, len(images)) :
feature = VGG16.predict(images[i]);
#variable description includes what the people are doing in this image : ["a man is cooking"]
description = descriptions[i];
#sequence includes things like ["a"ID, "man"ID, "is"ID, "cooking"ID], "xxx"ID is a digit of a word "xxx"
sequence = make_sequence(description);
yield [[feature, sequence], description];
//...
vgg_model = VGG16();
model = my_model();
generator = data_generator(images, descriptions, vgg_model);
model.fit_generator(generator, epochs = 1, verbose = 1, steps_per_epoch = 1);
The input of model is an image with its description, the output of model is the probability distribution of vocabulary. I want to use more advanced CNN ResNet 152, and it only available in tensorflow==2.2 with the latest version of keras. After I upgrade the tensorflow and keras, I got error :
ValueError: Layer model expects 2 input(s), but it received 3 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, None) dtype=float32>, <tf.Tensor 'IteratorGetNext:1' shape=(None, None) dtype=int32>, <tf.Tensor 'IteratorGetNext:2' shape=(None, None) dtype=float32>]
Because the code works well in old version tensorflow and keras, I think the origin of this problem is from data_generator
. How to modify this code to make it compatible with the latest version of tensorflow and keras?
Solution
I think you should play with what generator returns.
Change [[feature, sequence], description];
to this ([feature, sequence], description);
, because it expects x
and y
as a tuple.
Answered By - Kaveh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.