Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save last iterate output #609

Open
matthieutrs opened this issue Jul 7, 2023 · 4 comments
Open

Save last iterate output #609

matthieutrs opened this issue Jul 7, 2023 · 4 comments

Comments

@matthieutrs
Copy link

Hello and thanks for the support! Computing and saving the metrics returned by an algorithm is great, but it may also be interesting to save the outputs of the algorithm (the path to saved output could be returned in the saved dataframe).

Example of use case: running several imaging algorithms with benchopt and saving the images returned by each algorithm.

@tomMoral
Copy link
Member

tomMoral commented Jul 7, 2023

Just talked to @sylvchev who has the same need for trained BCI models.
We could expose a function save_last_run that takes in an output_dir path and returns a dict with information that will be saved in the DataFrame.

@Badr-MOUFAD
Copy link
Member

Badr-MOUFAD commented Jul 11, 2023

Thinking out load,

Inspired by the newly added warm_up method,
one way to implement this feature is to add a new SolverBase method post_run that takes the last result as input and performs some user-defined logic, in this case, it would be saving the output.

For instance, the following will be the user-defined method to save the output,

class Solver(BaseSolver):
    ...
	
    def post_run(self, result):
        x = result["x"]
	path = "PATH_WHERE_TO_SAVE_OUTPUT"

	    with open(path, 'wb') as f:
                np.save(f, x)
    ...

Any thoughts, @tomMoral @matthieutrs?

@matthieutrs
Copy link
Author

Yes, I think it would be nice to have an easily customizable function, just like hooks in torch lightning. In my case, I'd be interested only in saving after the last run, but post_run would be fine too.

@tomMoral
Copy link
Member

I would go for something like: process_last_run_result, but yes something customizable in the objective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants