-
Notifications
You must be signed in to change notification settings - Fork 11
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
Is there any method to generate image state? #48
Comments
@damienmarchal Have you done such things? |
I didn't tried it within SofaGym but I think that the approach to make rendering in Sofa is to use this plugin https://github.com/jnbrunet/SofaOffscreenCamera It may requires some work to make it work within SofaGym but I see no reason why it shouldn't be possible. |
I choose config parameter 'save_image' to True, and read written image in reward function. I think that render function in viewer.py is necessary to generate image and since I saw that visualization module and simulation module do not work in same process, file read/write approach is only way to get image. Do you also agree this approach? |
I also approach this method, but there is some build error. |
Hello @SangbaekYoo, Maybe you could try to override the If you also want to train this environment using stable baselines, you will need to modify the |
@samuelmyoussef Thank you for great advice, i will try your policy suggestion. I saw that add_new_step function in AbstractEnv.py does action and calculates reward and gets state.(action->reward->next_state) |
Yes, your implementation is similar to what I'm suggesting but it could be easier since you can just override your |
Hello @samuelmyoussef, and thank you for sharing various approaches. I see that if I define observation or state by big size image, since there is process to change (dictionary class <-> string), consumed time is very inefficient. So I decide to save image in Toolbox.py and read in step method. |
I don't think it will make much difference whether it's saving the image from the Toolbox or from To have a more efficient approach, you should look into what Damien linked about the offscreen camera since you won't have to launch the GUI just to save a state image. |
I have a pretty efficient solution in https://github.com/ScheiklP/sofa_env that does not require the GUI or SofaOffscreenCamera. I also have a rudimentary solution of multiple cameras in the same scene, but that did not yet make it into the upstream version of the repo. Maybe that could help? |
@ScheiklP What code can I reference? |
@SangbaekYoo
The camera is defined in the scene description. |
Hi, I am trying to do something similar. I want to use an image (or set of images) as my state. I am currently using just some coordinate points. In contrast to the original post I am happy with constructing the images myself and do not need them to be the same as the GUI. In order to make this change I understand I need to pass the image as my state and change the policy hyperparemeter to CnnPolicy instead of MlpPolicy. I assume I also need to somehow change my observation space in my env.py file to match the image I am passing as my state but I am unsure exactly how to do this? Is there anything else that I need to change in order to get this to work? |
your observation space will be something like this Other than this, you need to do the changes to make sure that your To use a set of images instead of one, I think there's a frame stack wrapper already implemented in gym that you can use to do so. |
I have the model training well with the images but I am unsure how to load the model once it is trained. When training a model with coordinate points i just use PPO.load() as I am using the PPO algo. However, with a customCNN passed into the PPO during training, PPO.load() no longer works to load the trained model. Is there another way of loading a trained model with a customCNN? |
Can you provide more details about the issue? What happens when you try to use |
This is the error I get when I try use PPO.load() to load the trained model with the customCNN:
|
@MarkWrobelUCL |
I actually just fixed my issue and that was not the problem. I needed to import my CustomCNN class before loading the model. This class was defined in the 'agents' folder. |
Hi, thank you for great works for SofaGym!
I currently study SofaGym and make my own environment.
In my reinforcement learning architecture, I want to define image state(or observation) which is related to GUI screen image.
For this, I defined additional camera in Scene python file as follows:
(I thought that InteractiveCamera can realize my wish :))
Next, I refer to viewer.py and find the code which can make image object as follows:
I checked that above image is same as GUI screen image.
By using above code and Interactive camera(defined as camera2), I implemented additional function that returns image in Toolbox python file.
However, there is some multi-thread error(I guess that problem is due to reinitialization such as Sofa.SofaGL.glewInit() and Sofa.SofaGL.draw(self.root)).
So I conclude that this is not good approach.
Is there any method to get screen image in Toolbox and Scene code python without GUI?
The text was updated successfully, but these errors were encountered: