Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network._build assumes input array spec is bounded #189

Open
ericzhao28 opened this issue Aug 23, 2019 · 1 comment
Open

Network._build assumes input array spec is bounded #189

ericzhao28 opened this issue Aug 23, 2019 · 1 comment

Comments

@ericzhao28
Copy link

ericzhao28 commented Aug 23, 2019

When defining a custom network, the Network class attempts to build by calling tensor_spec.sample_spec_nest to sample an input.
Line 134 in tf_agents/network/network.py:

def _build(self):
    if not self.built and self.input_tensor_spec is not None:
      random_input = tensor_spec.sample_spec_nest(
          self.input_tensor_spec, outer_dims=(1,))
      step_type = tf.expand_dims(time_step.StepType.FIRST, 0)
      self.__call__(random_input, step_type, None)

However, sample_spec_nest attempts to convert each part of the input tensor spec to a BoundedTensorSpec.
Line 331 in tf_agents/specs/tensor_spec.py:

    elif isinstance(spec, (TensorSpec, BoundedTensorSpec)):
      spec = BoundedTensorSpec.from_spec(spec)
      return sample_bounded_spec(
          spec, outer_dims=outer_dims, seed=seed_stream())

This results in a TypeError when a custom network consumes a (for example) Boolean array as part of its input.
For instance:

  File "/home/em/projects/ActiveDialogue/venv/lib/python3.6/site-packages/tf_agents/networks/network.py", line 179, in trainable_variables
    self._build()
  File "/home/em/projects/ActiveDialogue/venv/lib/python3.6/site-packages/tf_agents/networks/network.py", line 135, in _build
    self.input_tensor_spec, outer_dims=(1,))
  File "/home/em/projects/ActiveDialogue/venv/lib/python3.6/site-packages/tf_agents/specs/tensor_spec.py", line 338, in sample_spec_nest
    return tf.nest.map_structure(sample_fn, structure)
  File "/home/em/projects/ActiveDialogue/venv/lib/python3.6/site-packages/tensorflow_core/python/util/nest.py", line 536, in map_structure
    structure[0], [func(*x) for x in entries],
  File "/home/em/projects/ActiveDialogue/venv/lib/python3.6/site-packages/tensorflow_core/python/util/nest.py", line 536, in <listcomp>
    structure[0], [func(*x) for x in entries],
  File "/home/em/projects/ActiveDialogue/venv/lib/python3.6/site-packages/tf_agents/specs/tensor_spec.py", line 332, in sample_fn
    spec = BoundedTensorSpec.from_spec(spec)
  File "/home/em/projects/ActiveDialogue/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/tensor_spec.py", line 258, in from_spec
    minimum = getattr(spec, "minimum", dtype.min)
  File "/home/em/projects/ActiveDialogue/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/dtypes.py", line 186, in min
    raise TypeError("Cannot find minimum value of %s." % self)
TypeError: Cannot find minimum value of <dtype: 'bool'>

Is there a recommended workaround for this issue?

@ericzhao28 ericzhao28 changed the title Network._build assumption of BoundedArraySpec Network._build assumes input array spec is bounded Aug 23, 2019
@RR-28023
Copy link

Hi @ericzhao28, I've run into the same issue. Did you find a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants