Coder Social home page Coder Social logo

Comments (7)

runame avatar runame commented on September 28, 2024 1

Hi,

Unfortunately the library currently has no native support for saving and loading Laplace instances. However, you should be able to simply use pickle to store and load the whole class instance, i.e. by using something like

import pickle

def save_laplace(la, filepath):
    with open(filepath, 'wb') as output:
        pickle.dump(la, output)

def load_laplace(filepath):
    with open(filepath, 'rb') as input:
        la = pickle.load(input)
    return la

where la is your instance of last-layer Laplace after fitting and filepath is the path to the file in which you want to store the object. Just let me know if you run into issues with this approach.

We are planning to make this process more convenient in a future release, I have just opened an issue for this (#45).

from laplace.

roysubhankar avatar roysubhankar commented on September 28, 2024

Thank you for this workaround.

from laplace.

roysubhankar avatar roysubhankar commented on September 28, 2024

Hi @runame , I am getting this error when I am using your suggestion.

AttributeError: Can't pickle local object 'FeatureExtractor._get_hook..hook'

from laplace.

runame avatar runame commented on September 28, 2024

Ah I didn't test this approach with last-layer Laplace which uses the FeatureExtractor with nested functions and pickle can't handle this. Can you try using dill instead of pickle? Simply install it via pip install dill.

import dill

def save_laplace(la, filepath):
    with open(filepath, 'wb') as outpt:
        dill.dump(la, outpt)

def load_laplace(filepath):
    with open(filepath, 'rb') as inpt:
        la = dill.load(inpt)
    return la

from laplace.

runame avatar runame commented on September 28, 2024

@roysubhankar Did it work?

from laplace.

panos108 avatar panos108 commented on September 28, 2024

I had the same issue. It seems that the dill solved thanks!

from laplace.

runame avatar runame commented on September 28, 2024

Perfect, thanks for letting me know!

from laplace.

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.