简体   繁体   中英

fit_generator() doesn't works in Spyder

I am trying to use fit_generator() on Spyder for training a Neural Network (which I want to train for sorting out digit's images) and I always have the same problem. When I call the function the first result that I have is this one:

在此处输入图片说明

and then:

在此处输入图片说明

Basically, I do not understand what happen this. I will attach the code's segment.

X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.10, random_state=42)

batches     = gen.flow(X_train, y_train, batch_size=64) # batches.n = 37800
val_batches = gen.flow(X_val, y_val, batch_size=64) # val_batches.n = 4200


history=model.fit_generator(generator=batches, steps_per_epoch=batches.n, 
                              epochs=3,  validation_data=val_batches,
                              validation_steps=val_batches.n)

Could someone help me?

Thanks in advance.

I had the exact same problem and spent a few days searching the net for solutions / reinstalling a couple of times / nearly throwing my laptop out / giving up and gathering hope again / finally finding a solution. Special thanks to this GitHub post

Here's the step-by-step solution to what I did. I'm using a MacBook and Anaconda for python / Spyder:

  • Installed Anaconda (c1.9.6) and through it Python in the (base) environment [EDIT: It's the Anaconda version 2018.12 that I installed. The navigator Anaconda Navigator > About Anaconda Navigator states its Anaconda Navigator 1.9.6]
  • Through the Anaconda Navigator, created a new (deeplearning) environment
  • Again using the Navigator, I installed Keras, Tensorflow, Theano, Numpy, Pandas, Matplotlib, Scikit-learn, Spyder-kernels in the new (deeplearning) environment (and various associated packages were automatically installed)
  • Using Terminal, in my (base) environment, I downgraded my Python from 3.7 to 3.6.8 ( conda install python=3.6 ) so it would work with Keras [EDIT: This step may be redundant and not required]
  • Using Terminal, went into my (deeplearning) environment and installed nomkl ( conda install nomkl ) (it asked to downgrade some packages to which I said ok)
  • Still in my (deeplearning) environment in my Terminal, I typed python -c "import sys; print(sys.executable)" to get my path + copied the pathname
  • Opened Spyder through my (base) environment and navigated to Preferences > Python Interpreter > Use the following interpreter where I input my path
  • Restarted Spyder, again in the (base) environment and started coding. [EDIT: You may not need to restart Spyder. Rather just open a new console tab].

It all worked like a beauty. I can finally get on with learning more of this exciting field!

Just FYI... The first error image you get is not really an error, it's a warning that essentially means that the speed will not be as fast as it can be. The second image is the annoying error that took away a few days of my life to research a solution!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM