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

Regularizer Loss remains zero / BatchToSpaceND #175

Open
gargahcerk opened this issue May 20, 2020 · 1 comment
Open

Regularizer Loss remains zero / BatchToSpaceND #175

gargahcerk opened this issue May 20, 2020 · 1 comment

Comments

@gargahcerk
Copy link

Hello
thanks for this great respository!

I use the GammaFlopsRegularizer, but the regularization loss remains at 0.
Since I initially received the error message

"OpRegularizerManager could not handle ops: ['ForwardPass/w2l_encoder/conv121/BatchToSpaceND (BatchToSpaceND)', 'ForwardPass/w2l_encoder/conv121/SpaceToBatchND (SpaceToBatchND)', 'ForwardPass/w2l_encoder/conv121/concat_1 (Identity)']"

, I set the following in /network_regularizers/flop_regularizer.py:

    op_handler_dict.update({
        'FusedBatchNorm': source_op_handler,
        'FusedBatchNormV2': source_op_handler,
        'FusedBatchNormV3': source_op_handler,
        'BatchToSpaceND': leaf_op_handler.LeafOpHandler(),
        'SpaceToBatchND': leaf_op_handler.LeafOpHandler(),
    })

and also added BatchToSpaceND and SpaceToBatchND to the supported OPs in network_regularizers/cost_calculator.py.
I don't get any more error messages, but the regularization loss remains at zero. What can I do?

Thanks for your help !

@gargahcerk
Copy link
Author

gargahcerk commented May 26, 2020

I thought the problem was with BatchToSpace. I was able to prevent BatchToSpace from occurring (occurs when conv1d dilation > 1) and there is still the problem with Regularizer Loss = 0.0. The FLOPs can be calculated, so I assume that reg_outputs/ reg_inputs (network_regularizers/resource_function.py#L477) must be 0.

Further information:
I use the model Jasper (Openseq2seq). For Batch Normalization I set scale and fused = true. channels_last is set.

This is how I included morphnet:

def get_regularization_loss(self):
    from open_seq2seq.optimizers import get_regularization_loss as old_regularization_loss
    if not self.params['morphnet']:
      return old_regularization_loss()
    else:
      from morph_net.network_regularizers import flop_regularizer
      from morph_net.tools import structure_exporter

      network_regularizer = flop_regularizer.GammaFlopsRegularizer(output_boundary=[self._logits.op], input_boundary=[self.get_data_layer().input_tensors["source_tensors"][0].op,  self.get_data_layer().input_tensors["target_tensors"][0].op], gamma_threshold=1e-3)

      regularization_strength = 1e-10
      regularizer_loss = (network_regularizer.get_regularization_term() * regularization_strength)
      self.reg_loss = regularizer_loss
      self.reg_costs = network_regularizer.get_cost()

      tf.summary.scalar('RegularizationLoss', regularizer_loss)
      tf.summary.scalar(network_regularizer.cost_name, network_regularizer.get_cost())

      return tf.add(old_regularization_loss(),regularizer_loss)

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

1 participant