浏览代码

enforce line length

/develop-generalizationTraining-TrainerController
Chris Elion 5 年前
当前提交
2f9c3ed5
共有 4 个文件被更改,包括 21 次插入10 次删除
  1. 6
      .pre-commit-config.yaml
  2. 3
      gym-unity/gym_unity/envs/unity_env.py
  3. 15
      ml-agents/mlagents/trainers/tensorflow_to_barracuda.py
  4. 7
      setup.cfg

6
.pre-commit-config.yaml


)$
args: [--fix=lf]
- id: flake8
exclude: ".*_pb2.py"
exclude: >
(?x)^(
.*_pb2.py|
.*_pb2_grpc.py
)$

3
gym-unity/gym_unity/envs/unity_env.py


:param use_visual: Whether to use visual observation or vector observation.
:param uint8_visual: Return visual observations as uint8 (0-255) matrices instead of float (0.0-1.0).
:param multiagent: Whether to run in multi-agent mode (lists of obs, reward, done).
:param flatten_branched: If True, turn branched discrete action spaces into a Discrete space rather than MultiDiscrete.
:param flatten_branched: If True, turn branched discrete action spaces into a Discrete space rather than
MultiDiscrete.
:param no_graphics: Whether to run the Unity simulator in no-graphics mode
:param allow_multiple_visual_obs: If True, return a list of visual observations instead of only one.
"""

15
ml-agents/mlagents/trainers/tensorflow_to_barracuda.py


op="Flatten",
input=[
inputs[-1]
], # take only the last input, assume all other arguments are trivial (like sequence_length==1 always in ML-agents LSTM nets)
], # take only the last input, assume all other arguments are trivial (like sequence_length==1
# always in ML-agents LSTM nets)
),
"Reshape": lambda nodes, inputs, tensors, context: Struct(
op="Reshape",

input=[i for i in inputs]
+ [t.name for t in tensors][1:][
-2:
], # [1:] - skips the 0th tensor, since Conv2DBackpropInput 0th tensor is 'input_sizes' (which differs from other Conv layers)
], # [1:] - skips the 0th tensor, since Conv2DBackpropInput 0th tensor is 'input_sizes'
# (which differs from other Conv layers)
# [-2:] - take only last 2 tensors, this allows to process large patterns with the same code
padding=get_attr(by_op(nodes, "Conv2DBackpropInput"), "padding"),
strides=get_attr(by_op(nodes, "Conv2DBackpropInput"), "strides"),

end = end.astype(np.int32).tolist()
strides = strides.astype(np.int32).tolist()
# StridedSlice range and mask descriptions: https://www.tensorflow.org/api_docs/cc/class/tensorflow/ops/strided-slice
# StridedSlice range and mask descriptions:
# https://www.tensorflow.org/api_docs/cc/class/tensorflow/ops/strided-slice
# TODO: I don't think elipsis and newaxis would work together well with current implementation
assert len(begin) == len(end)

# filter only inputs that are coming from nodes that are outside this pattern
# preserve the order
pattern_nodes = [n.name for n in pattern_nodes] + tensor_names
# inputs_from_outside_pattern = remove_duplicates_from_list([i for i in inputs_to_op_nodes if nodes_by_name[i] not in pattern_nodes])
# inputs_from_outside_pattern = remove_duplicates_from_list([i for i in inputs_to_op_nodes if
# nodes_by_name[i] not in pattern_nodes])
inputs_from_outside_pattern = remove_duplicates_from_list(
[i for i in inputs_to_op_nodes if i not in pattern_nodes]
)

Converts a TensorFlow model into a Barracuda model.
:param source_file: The TensorFlow Model
:param target_file: The name of the file the converted model will be saved to
:param trim_unused_by_output: The regexp to match output nodes to remain in the model. All other uconnected nodes will be removed.
:param trim_unused_by_output: The regexp to match output nodes to remain in the model.
All other unconnected nodes will be removed.
:param verbose: If True, will display debug messages
:param compress_f16: If true, the float values will be converted to f16
:return:

7
setup.cfg


[flake8]
# black will apply a line length of 88 to code but not docstrings/comments
# This seems like a decent compromise between readability and redoing all the docstrings.
max-line-length=120
# Line length - handled by black, should be doable with a line length setting too
E501,
# Black
W503,

正在加载...
取消
保存