GithubHelp home page GithubHelp logo

train error:ValueError: Input arrays should have the same number of samples as target arrays about keras-transfer-learning-for-oxford102 HOT 11 CLOSED

arsey avatar arsey commented on August 11, 2024
train error:ValueError: Input arrays should have the same number of samples as target arrays

from keras-transfer-learning-for-oxford102.

Comments (11)

Arsey avatar Arsey commented on August 11, 2024

probably corrupted dataset

from keras-transfer-learning-for-oxford102.

djones4487169 avatar djones4487169 commented on August 11, 2024

Did you manage to get this working? I have the following error in bootstrap.py:

move_files('train', labels[idx_test, :])
Index Error: too many indices

Any ideas? Do you have a fully working version you could send please?

from keras-transfer-learning-for-oxford102.

cottontail7 avatar cottontail7 commented on August 11, 2024

check vgg16.py
ImageDataGenerator.flow_from_directory() has a default batch_size, predict_generator() take parameter steps, in the script steps=config.nb_train_samples, which means you are getting nb_train_samples*batch_size samples from the generator, you can set batch_size=1 or steps=config.nb_train_samples/batch_size
I guess in older versions of keras the input parameter acctually takes the whole number of samples to be generated. I'm using keras2.0.4

from keras-transfer-learning-for-oxford102.

djones4487169 avatar djones4487169 commented on August 11, 2024

I'm using keras 2.0.4. We have this function in save_bottleneck_features() in vgg16.py:

generator = datagen.flow_from_directory(
config.train_dir,
target_size=config.img_size,
shuffle=False,
classes=config.classes)
bottleneck_features_train = model.predict_generator(generator, config.nb_train_samples)

What do I need to change? Do I do the same for validation?

from keras-transfer-learning-for-oxford102.

cottontail7 avatar cottontail7 commented on August 11, 2024

@djones4487169
Add batch_size=1 to the parameters, do the same for validation. Also you may need to modify tune(). You can check keras.io for how those functions works.

Making these modifications will get you through save_bottleneck_features() & train_top_model(), there are some other problems when running tune(), I haven't looked into them. You may want to consider using a lower version of keras to run the scripts directly.

from keras-transfer-learning-for-oxford102.

djones4487169 avatar djones4487169 commented on August 11, 2024

I got it working up to model fitting and 1st epoch but then:

ResourceExhaustedError: OOM when allocating tensor with shape [4096,4096]

Any ideas how to solve this or free up memory to allow it fit the model?

from keras-transfer-learning-for-oxford102.

djones4487169 avatar djones4487169 commented on August 11, 2024

Got it training by changing 4096 in both dense layers to 1024 and then 256.

from keras-transfer-learning-for-oxford102.

djones4487169 avatar djones4487169 commented on August 11, 2024

Error in tune():

Negative dimension size caused by subtracting 2 from 1 for 'block2_pool_1/MaxPool' with input shapes: [?,1,112,128]

I'm using tensorflow backend?

from keras-transfer-learning-for-oxford102.

djones4487169 avatar djones4487169 commented on August 11, 2024

Changed:
basee_model = VGG16(weights='imagenet', include_top=False, input_tensor=Input(shape=(3,) + config.img_size))

To:
base_model = VGG16(weights='imagenet', include_top=False, input_tensor=Input(shape=(224, 224, 3)))

from keras-transfer-learning-for-oxford102.

djones4487169 avatar djones4487169 commented on August 11, 2024

Any ideas about this error in function get_top_model_for_VGG16() in vgg16.py :

you called 'set_weights' on layer 'fc1' with a weight list of length 1, but it was expecting 2 weights

from keras-transfer-learning-for-oxford102.

Arsey avatar Arsey commented on August 11, 2024

@djones4487169, the code does not support TensorFlow, please use Theano.
@cottontail7, I didn't test the code with Keras 2, I would suggest using Keras 1.2 with it as Keras 2 has some issues with weights of pre-trained models

from keras-transfer-learning-for-oxford102.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.