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

transferrable models #70

Closed
blurLake opened this issue Jun 23, 2020 · 5 comments · Fixed by #138
Closed

transferrable models #70

blurLake opened this issue Jun 23, 2020 · 5 comments · Fixed by #138
Labels
custom gym env Issue related to Custom Gym Env documentation Improvements or additions to documentation question Further information is requested

Comments

@blurLake
Copy link
Contributor

Hi, is there a way to save a model only with the internal layers of the NN? Or is it possible to modify a trained model (the zip file), to let it retrain with different action dimension?

I am thinking the following example, say we have env_1 with action dimension 10, and env_2, which is more complicated version of env_1, with action dimension 20. One model is trained with env_1. Can we modify the model (zip file) and use it as initial value to train on env_2 afterwards?

Thank you very much!

@araffin araffin added question Further information is requested custom gym env Issue related to Custom Gym Env labels Jun 23, 2020
@Miffyli
Copy link
Collaborator

Miffyli commented Jun 23, 2020

You can do this with original stable-baselines using get_parameters and load_parameters, and with bit of manual tinkering. You need manually create the mismatching parameter arrays for env_2 agent and update correct parameters with ones from env_1 agent. E.g. if only the last fully-connected layer changes, you need to manually crate final_params = np.zeros((N, 20)) and then assign the weights of original parameters to it final_params[:, :10] = original_params. If you want to modify save .zip files, the format is specified here.

Similar support is planned / partially working in SB3, but still needs to go through a check and review.

@bektaskemal
Copy link

So, is exporting saved model as Pytorch model not supported yet in SB3? Is there a way to get model parameters as in stable-baselines' get_parameters function?

@araffin
Copy link
Member

araffin commented Jun 26, 2020

So, is exporting saved model as Pytorch model not supported yet in SB3?

It is for policy. (but not properly documented yet). There are nn.Module anyway.

@araffin araffin added the documentation Improvements or additions to documentation label Jun 26, 2020
@bektaskemal
Copy link

bektaskemal commented Jun 26, 2020

Thanks for reply. I have a related question. I was considering exporting actor network only but I noticed that model.predict and model.actor.predict returns different values. Is it expected behavior?

model = SAC('MlpPolicy', 'CartPole-v1', verbose=1)
env = gym.make ('CartPole-v1')
obs = env.reset()
print(model.predict(obs))
print(model.actor.predict(obs))

Returns: (array([-0.20559013], dtype=float32), None)
(array([-0.9510132], dtype=float32), None)

Edit: My mistake. It works as expected when both is called as deterministic.

@araffin
Copy link
Member

araffin commented Sep 24, 2020

Similar support is planned / partially working in SB3, but still needs to go through a check and review.

done in #138 (will merge today)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
custom gym env Issue related to Custom Gym Env documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants