udacity / CarND-Behavioral-Cloning-P3

Starting files for the Udacity CarND Behavioral Cloning Project
https://www.udacity.com/drive
MIT License
438 stars 1.71k forks source link

Simulator Load File error #6

Closed timtobey closed 7 years ago

timtobey commented 7 years ago

Dear Manav: I get a load file error when I run: python drive.py model.h5

(BTW, There is some confusion in the community if the h5 file or the json file should be loaded.)

I run : python drive.py model.h5

I get on my windows 10 machine: Using TensorFlow backend. Traceback (most recent call last): File "drive.py", line 83, in model = load_model(args.model) File "d:\kits\Anaconda3\envs\carnd-term1\lib\site-packages\keras\models.py", line 140, in load_model raise ValueError('No model found in config file.') ValueError: No model found in config file.

Here is my save code: .......... model.summary() model.compile(optimizer='adam', loss='mse', metrics=['accuracy']) history = model.fit(X_train, y_train, nb_epoch=10, batch_size=2000, verbose=1, validation_data=(X_validation, y_validation)) score = model.evaluate(X_validation, y_validation) print('Test score:', score[0]) print('Test accuracy:', score[1]) print("\nSaving model weights and configuration file.") with open('model.json', 'w') as f: f.write(model.to_json()) model.save_weights('model.h5') f.close() print("Saved model to disk") from keras import backend as K K.clear_session()

Thanks for any guidance you can provide me.

domluna commented 7 years ago

Try model.save('model.h5') instead of model.save_weights('model.h5').

timtobey commented 7 years ago

You are a Genius! Thanks it works. If you dont mind, can you explain to me why the model save would works and not the weights? Thank you so much I have been stuck on this for days!

domluna commented 7 years ago

save also saves the configuration of the network, i.e. how it's structured while save_weights only saves the weights. load_model needs to reconstruct the model and it can't do this with only knowledge of the weight values.

timtobey commented 7 years ago

That clears things up. Thanks again!