keras - What should the generator passed to predict_generator() return? -


i calling keras predict_generator() like:

bottleneck_features_train = model.predict_generator(train_gen, len(telemetry))

where train_gen() defined like

def train_gen(): # ... yield (x, y)

and x numpy array shape (48, 299, 299, 3), y numpy array shape (48,)

i error below. should instead?

otherwise, link working example help. examples have found keras 1 or using imagedatagenerator.flow().

i running keras 2.0.2.

here error:

traceback (most recent call last):   file "/home/fanta/workspace/carnd-behavioral-cloning-p3/cache.py", line 143, in <module>     tf.app.run()   file "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 44, in run     _sys.exit(main(_sys.argv[:1] + flags_passthrough))   file "/home/fanta/workspace/carnd-behavioral-cloning-p3/cache.py", line 138, in main     bottleneck_features_train = model.predict_generator(train_gen, len(telemetry))   file "/usr/local/lib/python3.5/dist-packages/keras/legacy/interfaces.py", line 88, in wrapper     return func(*args, **kwargs)   file "/usr/local/lib/python3.5/dist-packages/keras/engine/training.py", line 2094, in predict_generator     outs = self.predict_on_batch(x)   file "/usr/local/lib/python3.5/dist-packages/keras/engine/training.py", line 1677, in predict_on_batch     self._feed_input_shapes)   file "/usr/local/lib/python3.5/dist-packages/keras/engine/training.py", line 100, in _standardize_input_data     'found: array shape ' + str(data.shape)) valueerror: model expects 0 input arrays, received 1 array. found: array shape (48, 299, 299, 3)  process finished exit code 1 

===== update =====

the issue not related generator. here below short program reproduce it. note if switch network inception vgg, works fine.

from keras.applications.inception_v3 import inceptionv3 keras.applications.vgg16 import vgg16 keras.layers import input, averagepooling2d keras.models import model keras.datasets import cifar10 scipy.misc import imresize import pickle import tensorflow tf import keras.backend k import numpy np  network='inception'  # must 'inception' or 'vgg' dataset='cifar10' batch_size=64  if network == 'vgg':     size = (224, 224) elif network == 'inception':     size = (299, 299) else:     assert false, "network must either 'inception' or 'vgg'"  def create_model():     input_tensor = input(shape=(size[0], size[1], 3))     if network == 'inception':         model = inceptionv3(input_tensor=input_tensor, include_top=false)         x = model.output         x = averagepooling2d((8, 8), strides=(8, 8))(x)         model = model(model.input, x)     elif network == 'vgg':         model = vgg16(input_tensor=input_tensor, include_top=false)         x = model.output         x = averagepooling2d((7, 7))(x)         model = model(model.input, x)     else:         assert false     return model  def main():      # download , load cifar10 dataset     (x_train, y_train), (_, _) = cifar10.load_data()      # reduce dataset first 1000 entries, save memory , computation time     x_train = x_train[0:1000]     y_train = y_train[0:1000]      # resize dataset images comply expected input image size     x_train = [imresize(image, size) image in x_train]     x_train = np.array(x_train)      # file name save bottlenecked features     train_output_file = "{}_{}_{}.p".format(network, dataset, 'bottleneck_features_train')     print("saving to", train_output_file)      tf.session() sess:         k.set_session(sess)         k.set_learning_phase(1)         model = create_model()         # skip pre-processing , bottleneck features         bottleneck_features_train = model.predict(x_train, batch_size=batch_size, verbose=1)         data = {'features': bottleneck_features_train, 'labels': y_train}         pickle.dump(data, open(train_output_file, 'wb'))  if __name__ == '__main__':     main() 

at prediction step generator should yield input , not targets. x, not y.

does help?


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -