浏览代码

image decompress timer (#2596)

* image decompress timer

* dont lazy load the image
/develop-gpu-test
GitHub 5 年前
当前提交
43c13a35
共有 1 个文件被更改,包括 7 次插入2 次删除
  1. 9
      ml-agents-envs/mlagents/envs/brain.py

9
ml-agents-envs/mlagents/envs/brain.py


from mlagents.envs.communicator_objects.brain_parameters_proto_pb2 import (
BrainParametersProto,
)
from mlagents.envs.timers import hierarchical_timer, timed
from typing import Dict, List, Optional
from PIL import Image

return np.append(m1, m2, axis=0)
@staticmethod
@timed
def process_pixels(image_bytes: bytes, gray_scale: bool) -> np.ndarray:
"""
Converts byte array observation image into numpy array, re-sizes it,

:return: processed numpy array of observation from environment
"""
image_bytearray = bytearray(image_bytes)
image = Image.open(io.BytesIO(image_bytearray))
with hierarchical_timer("image_decompress"):
image_bytearray = bytearray(image_bytes)
image = Image.open(io.BytesIO(image_bytearray))
# Normally Image loads lazily, this forces it to do loading in the timer scope.
image.load()
s = np.array(image) / 255.0
if gray_scale:
s = np.mean(s, axis=2)

正在加载...
取消
保存