MCPcopy Create free account
hub / github.com/YeWR/EfficientZero / str_to_arr

Function str_to_arr

core/utils.py:331–348  ·  view source on GitHub ↗

To reduce memory usage, we choose to store the jpeg strings of image instead of the numpy array in the buffer. This function decodes the observation numpy arr from the jpeg strings Parameters ---------- s: string the inputs gray_scale: bool True -> the inputs obse

(s, gray_scale=False)

Source from the content-addressed store, hash-verified

329
330
331def str_to_arr(s, gray_scale=False):
332 """To reduce memory usage, we choose to store the jpeg strings of image instead of the numpy array in the buffer.
333 This function decodes the observation numpy arr from the jpeg strings
334 Parameters
335 ----------
336 s: string
337 the inputs
338 gray_scale: bool
339 True -> the inputs observation is gray not RGB.
340 """
341 nparr = np.frombuffer(s, np.uint8)
342 if gray_scale:
343 arr = cv2.imdecode(nparr, cv2.IMREAD_GRAYSCALE)
344 arr = np.expand_dims(arr, -1)
345 else:
346 arr = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
347
348 return arr

Callers 2

obsMethod · 0.90
step_obsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected