Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.
This repository was archived by the owner on May 9, 2025. It is now read-only.

[feature improving request (srl_zoo)] Around 30% speed-up by changing few lines code #46

@ncble

Description

@ncble

Problem description

In the current (origin/master) version, there are two preprocessing mode: 1. 'tf' and 2. 'image_net'. I have noticed that with the some device/python environment/encoder model/robot environment etc, the option 'image_net' provide 30% speed-up compared to 'tf'.

Reproduce the problem

  • Under robotics-rl-srl/
    $ python -m environments.dataset_generator --env MobileRobotGymEnv-v0 --name mobile2D_fixed_tar_seed_0 --seed 0 --num-cpu 8
  • Modify the script srl_zoo/preprocessing/utils.py so that the preprocessing mode is 'tf'
  • Under srl_zoo/
    $ python train.py --data-folder mobile2D_fixed_tar_seed_0 --losses autoencoder

With the original version of srl_zoo, the training time per epoch of autoencoder (under 'tf' mode) is about 43s on my computer and with the following modification, the time reduces to 31s.

Solution

I propose to change the script srl_zoo/preprocessing/utils.py (both the functions preprocessInput and deNormalize.

  def preprocessInput(x, mode="tf"):
      ....
      assert x.shape[-1] == 3, "Color channel must be at the end of the tensor {}".format(x.shape)
      x /= 255.
      if mode == "tf":
          # x -= 0.5
          # x *= 2.
          ## The following code is 33% faster than above one.
          x[..., 0] -= 0.5
          x[..., 1] -= 0.5
          x[..., 2] -= 0.5
          x[..., 0] *= 2.
          x[..., 1] *= 2.
          x[..., 2] *= 2.

deNormalize is similar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions