Comments (6)
Hi @DamienAllonsius. I'm not quite clear on what you want to do. I'm assuming you want to transform the observations the agent gets by processing them as RGB images?
One thing you should be aware of is that the image that you see when running manual_control.py
, that is the human-viewable input, is not the same as what the agent sees. The agent gets a partially observable view of the environment that is encoded as a (7,7,3) array, which is not an image, but rather a symbolic encoding of the grid cells in front of the agent. What you see in manual_control.py
is a rendering of the whole grid as an RGB image, which is produced by a call to env.render('human')
.
The easiest way to transform what the agent sees is using a wrapper, see the code in wrappers.py
for some examples. There is a wrapper that transforms the input the agent gets into an RGB image, which may be a good starting point for what you want to do.
from minigrid.
Hi @maximecb Thanks a lot for your answer !
No, I really want to transform the rendering, not the observation.
I already give this observation to my agent
env.render(mode='rgb_array', highlight=False)
But then I transform the matrix by applying some downsampling with cv2
, and I would like to see the result of it. Is that possible ? Thanks a lot Maxime
(sinon je suis français, on peut aussi communiquer par mail en français si tu préfères)
Damien
from minigrid.
You would have to modify the renderer class or create your own window using PyQT or Pyglet. The slightly annoying part is that you have to convert the rgba array into a QPixmap object, basically. Then the Window
class here has a setPixmap
method that you can use: https://github.com/maximecb/gym-minigrid/blob/master/gym_minigrid/rendering.py#L55
It's a bit annoying but definitely doable: https://stackoverflow.com/questions/34232632/convert-python-opencv-image-numpy-array-to-pyqt-qpixmap-image
If you do it, maybe you could add a method to the Window
class to set what is being displayed from a numpy rgba array and create a pull request? :)
from minigrid.
Thanks for your answer. Ok I'm on it.
from minigrid.
Following the stackoverflow advices, I made a new function in Renderer
class
def drawArray(self, rgb_array):
from PyQt5.QtGui import QPixmap
height, width, _ = rgb_array.shape
bytes_per_line = 3 * width
qt_img = QImage(rgb_array, width, height, bytes_per_line, QImage.Format_RGB888) # .rgbSwapped()
pixmap = QPixmap(qt_img)
if self.window.closed:
self.window = None
else:
self.window.setPixmap(pixmap)
self.app.processEvents()
But I get a segmentation fault
when I run it. Any Idea ?
from minigrid.
I don't think that you can just pass the numpy array directly. You will need to get a pointer to the data it contains using ctypes
. Something like:
import ctypes
rgb_array = np.ascontiguousarray(rgb_array)
ptr = rgb_array.ctypes.data_as(ctypes.POINTER(ctypes.c_char))
qt_img = QImage(ptr, ...)
The ascontiguousarray call is to make sure the memory is all in one contiguous block.
References:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.ctypes.html
https://docs.python.org/3/library/ctypes.html
from minigrid.
Related Issues (20)
- [Question] Use of 'direction' in observation space? HOT 1
- [Bug Report] Toggling the box will make it disappear HOT 2
- [Bug Report] Error when creating BabyAI environment HOT 2
- [Question] Field of view algorithm explanation
- [Question] What do you mean by "done" action in the action space? HOT 3
- [Bug Report] Spec.to_json() of SimpleCrossing fails
- [Question] Getting total number of unique states HOT 1
- [Question] How to create vectorized envs for minigrid HOT 3
- [Bug Report] Unlock Pickup env is actually just Unlock HOT 4
- [Question] Difference between Minigrid and BabyAI envs HOT 1
- [Question] Is `ActionBonus` wrapper correct ? HOT 1
- [Question] How to build custom environment with custom action space HOT 1
- Python 3.11 support is missing from the README
- [Proposal] Update documentation HOT 3
- [Proposal] Add relevant project
- [Proposal] Discrete observations
- [Bug Report] ViewSizeWrapper ignored with RGBImgPartialObsWrapper HOT 1
- [Question] Get demonstration for 'MiniGrid-MultiRoom-N4-S5-v0' HOT 1
- [Bug Report] Cannot decode obs['image'] because of no implementation of agent in minigrid/core/world_object.py
- Accessing Specific Mission in BabyAI HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minigrid.