Skip to content

Switch boolean_mask to dynamic_partition #2

Description

@beangoben

Hi as a suggestion when computing the WGAN loss in your descriminator.
Newer versions of tensorflow will throw a warning an error at the usage of bolean_mask with sparse and shape changing tensors (for example when switching the batch size, fro a training/test set).

It is suggested to replace with dynamic_partition.

The warning will be:

UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. 
This may consume a large amount of memory.
"Converting sparse IndexedSlices to a dense Tensor of unknown shape. "

The original code is:

xy_neg = tf.boolean_mask(tf.transpose(self.scores), tf.cast(self.input_y[:, 0], tf.bool))
xy_pos = tf.boolean_mask(tf.transpose(self.scores), tf.cast(self.input_y[:, 1], tf.bool))

the change would look like this:

parts = tf.dynamic_partition(self.scores,  tf.cast(self.input_y[:, 1], tf.int32l), 2)
xy_neg = parts[0]
xy_pos = parts[1]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions