Insights Blog
-- Browse All Articles --
Physics Articles
Physics Tutorials
Physics Guides
Physics FAQ
Math Articles
Math Tutorials
Math Guides
Math FAQ
Education Articles
Education Guides
Bio/Chem Articles
Technology Guides
Computer Science Tutorials
Forums
Chemistry
Biology and Medical
Earth Sciences
Computer Science
Computing and Technology
DIY Projects
Trending
Featured Threads
Log in
Register
What's new
Search
Search
Search titles only
By:
Chemistry
Biology and Medical
Earth Sciences
Computer Science
Computing and Technology
DIY Projects
Menu
Log in
Register
Navigation
More options
Contact us
Close Menu
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Other Sciences
Computing and Technology
Load model in TensorFlow gives a different result than the original one
Reply to thread
Message
[QUOTE="Gaussian97, post: 6450190, member: 662184"] [B]TL;DR Summary:[/B] I'm using the TensorFlow library in Python. After creating a model and saving it, if I load the entire model, I get inconsistent results. First of all, I'm using TensorFlow version 2.3.0 The code I'm using is the following: [CODE=python] from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D from tensorflow.keras.callbacks import ModelCheckpoint def get_new_model(): model = Sequential([ Conv2D(filters=16, input_shape=(32, 32, 3), kernel_size=(3, 3), activation='relu', name='conv_1'), Conv2D(filters=8, kernel_size=(3, 3), activation='relu', name='conv_2'), MaxPooling2D(pool_size=(4, 4), name='pool_1'), Flatten(name='flatten'), Dense(units=32, activation='relu', name='dense_1'), Dense(units=10, activation='softmax', name='dense_2') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) return model checkpoint_path = 'model_checkpoints' checkpoint = ModelCheckpoint(filepath=checkpoint_path, save_weights_only=False, frequency='epoch', verbose=1) model = get_new_model() model.fit(x_train, y_train, epochs=3, callbacks=[checkpoint]) [/CODE] Until here no problem, I create the model, compile it and train it with some data. I also use ModelCheckpoint to save the model. The problem comes when I try the following [CODE=python]from tensorflow.keras.models import load_model model2 = load_model(checkpoint_path) model.evaluate(x_test, y_test) model2.evaluate(x_test, y_test)[/CODE] Then, the first evaluation returns an accuracy of 0.477, while the other returns an accuracy of 0.128, which is essentially a random choice. Where's the error? The two models are supposed to be identical, and actually, they give the same value for the loss function up to 16 decimal places. [/QUOTE]
Insert quotes…
Post reply
Forums
Other Sciences
Computing and Technology
Load model in TensorFlow gives a different result than the original one
Back
Top