Close Menu
    Trending
    • Your Team Will Love This Easy-to-Use PDF Editor
    • Patterns at Your Fingertips: A Practitioner’s Journey into Fingerprint Classification | by Everton Gomede, PhD | Jun, 2025
    • Get Microsoft 365 for Six People a Year for Just $100
    • The Age of Thinking Machines: Are We Ready for AI with a Mind of Its Own? | by Mirzagalib | Jun, 2025
    • Housing Market Hits a Record, More Sellers Than Buyers
    • Gaussian-Weighted Word Embeddings for Sentiment Analysis | by Sgsahoo | Jun, 2025
    • How a Firefighter’s ‘Hidden’ Side Hustle Led to $22M in Revenue
    • Hands-On CUDA ML Setup with PyTorch & TensorFlow on WSL2
    Finance StarGate
    • Home
    • Artificial Intelligence
    • AI Technology
    • Data Science
    • Machine Learning
    • Finance
    • Passive Income
    Finance StarGate
    Home»Machine Learning»Model Load get different result after restart runtime | by Ted James | Apr, 2025
    Machine Learning

    Model Load get different result after restart runtime | by Ted James | Apr, 2025

    FinanceStarGateBy FinanceStarGateApril 13, 2025No Comments2 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    I’ve written a Resnet50 mannequin utilizing google colab. After practice my mannequin then saving fashions afterwards load mannequin with out restart run time get identical end result, however when restarting runtime google colab and working xtrain, ytest, x_val, y_val then loading mannequin once more, I get totally different end result.

    right here is my code:

    #hyperparameter and callback
    batch_size = 128
    num_epochs = 120
    input_shape = (48, 48, 1)
    num_classes = 7

    #Compile the mannequin.
    from keras.optimizers import Adam, SGD
    mannequin = ResNet50(input_shape = (48, 48, 1), lessons = 7)
    optimizer = SGD(learning_rate=0.0005)
    mannequin.compile(optimizer= optimizer, loss='sparse_categorical_crossentropy', metrics=['accuracy'])

    mannequin.abstract()
    historical past = mannequin.match(
    data_generator.stream(xtrain, ytrain,),
    steps_per_epoch=len(xtrain) / batch_size,
    epochs=num_epochs,
    verbose=1,
    validation_data= (x_val,y_val))

    import matplotlib.pyplot as plt
    mannequin.save('Fix_Model_resnet50editSGD5st.h5')

    #plot graph
    accuracy = historical past.historical past['accuracy']
    val_accuracy = historical past.historical past['val_accuracy']
    loss = historical past.historical past['loss']
    val_loss = historical past.historical past['val_loss']
    num_epochs = vary(len(accuracy))
    plt.plot(num_epochs, accuracy, 'r', label='Coaching acc')
    plt.plot(num_epochs, val_accuracy, 'b', label='Validation acc')
    plt.title('Coaching and validation accuracy')
    plt.ylabel('accuracy')
    plt.xlabel('epoch')
    plt.legend()
    plt.determine()
    plt.plot(num_epochs, loss, 'r', label='Coaching loss')
    plt.plot(num_epochs, val_loss, 'b', label='Validation loss')
    plt.title('Coaching and validation loss')
    plt.ylabel('loss')
    plt.xlabel('epoch')
    plt.legend()
    plt.present()

    #load mannequin
    from keras.fashions import load_model
    model_load = load_model('Fix_Model_resnet50editSGD5st.h5')

    model_load.abstract()

    testdatamodel = model_load.consider(xtest, ytest)
    print("Take a look at Loss " + str(testdatamodel[0]))
    print("Take a look at Acc: " + str(testdatamodel[1]))

    traindata = model_load.consider(xtrain, ytrain)
    print("Take a look at Loss " + str(traindata[0]))
    print("Take a look at Acc: " + str(traindata[1]))

    valdata = model_load.consider(x_val, y_val)
    print("Take a look at Loss " + str(valdata[0]))
    print("Take a look at Acc: " + str(valdata[1]))

    -after coaching and saving mannequin then run load mannequin with out restart runtime google colab : as you possibly can see the

    Take a look at loss: 0.9411 — accuracy: 0.6514

    Prepare loss: 0.7796 — accuracy: 0.7091

    ModelEvaluateTest & Train

    simply run load mannequin once more after restart runtime colab:

    Take a look at loss: 0.7928 — accuracy: 0.6999

    Prepare loss: 0.8189 — accuracy: 0.6965

    after Restart Runtime Evaluate test and train

    You could set random seed to get identical outcomes on each iteration both in identical session or publish restarting.

    tf.random.set_seed(
    seed
    )

    test https://www.tensorflow.org/api_docs/python/tf/random/set_seed

    Answered By — Sarvesh Dubey

    Reply Checked By — Mary Flores (FixIt Volunteer)

    This Reply collected from stackoverflow, is licensed beneath cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleIs Jeff Bezos-Backed Slate Auto Making a ‘Cheap’ EV Truck?
    Next Article JPMorgan CEO Jamie Dimon: Bank Is Preparing for Turbulence
    FinanceStarGate

    Related Posts

    Machine Learning

    Patterns at Your Fingertips: A Practitioner’s Journey into Fingerprint Classification | by Everton Gomede, PhD | Jun, 2025

    June 1, 2025
    Machine Learning

    The Age of Thinking Machines: Are We Ready for AI with a Mind of Its Own? | by Mirzagalib | Jun, 2025

    June 1, 2025
    Machine Learning

    Gaussian-Weighted Word Embeddings for Sentiment Analysis | by Sgsahoo | Jun, 2025

    June 1, 2025
    Add A Comment

    Comments are closed.

    Top Posts

    機器學習複習系列(10)-神經網絡算法

    May 1, 2025

    OpenAI’s new agent can compile detailed reports on practically any topic

    February 3, 2025

    Graph Representation Learning using Graph Transformers !! | by Sarvesh Khetan | Mar, 2025

    March 16, 2025

    Franchising in 2025 — Best Bets and Biggest Challenges

    February 13, 2025

    Generative Imaging AI Will Use Game Engines and Synthetic Data to Train Models

    February 19, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    Most Popular

    Mission Impossible: An AI Agent that knows everything | by Michael Reppion | May, 2025

    May 30, 2025

    Starbucks CEO To Workers After Layoffs: We’re Not Effective

    March 7, 2025

    Model Load get different result after restart runtime | by Ted James | Apr, 2025

    April 13, 2025
    Our Picks

    Hierarchical Clustering with Example – Asmamushtaq

    February 8, 2025

    How to Master Mental Clarity and Find Your Focus

    May 10, 2025

    Anthropic’s Claude Opus 4 AI Model Is Capable of Blackmail

    May 23, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 Financestargate.com All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.