class_docstr: Mask predictor head
  
  Parameters
  ----------
  batch_images : int
      Used to reshape output
  classes : iterable of str
      Used to determine number of output channels, and store class names
  mask_channels : int
      Used to determine number of hidden channels
  num_fcn_convs : int, default 0
      number of convolution blocks before deconv layer. For FPN network this is typically 4.
class_docstr_tok: ["Mask","predictor","head","Parameters","--","--","--","--","--","batch_images",":","int","Used","to","reshape","output","classes",":","iterable","of","str","Used","to","determine","number","of","output","channels",",","and","store","class","names","mask_channels",":","int","Used","to","determine","number","of","hidden","channels","num_fcn_convs",":","int",",","default","0","number","of","convolution","blocks","before","deconv","layer",".","For","FPN","network","this","is","typically","4","."]
docstr: Reset class for mask branch.
docstr_tok: ["Reset","class","for","mask","branch","."]
code: def reset_class(self, classes, reuse_weights=None):
      """Reset class for mask branch."""
      if reuse_weights:
          assert hasattr(
              self, "classes"
          ), "require old classes to reuse weights"
      old_classes = getattr(self, "classes", [])
      self.classes = classes
      if isinstance(reuse_weights, (dict, list)):
          if isinstance(reuse_weights, dict):
              # trying to replace str with indices
              for k, v in reuse_weights.items():
                  if isinstance(v, str):
                      try:
                          v = old_classes.index(
                              v
                          )  # raise ValueError if not found
                      except ValueError:
                          raise ValueError(
                              "{} not found in old class names {}".format(
                                  v, old_classes
                              )
                          )
                      reuse_weights[k] = v
                  if isinstance(k, str):
                      try:
                          new_idx = self.classes.index(
                              k
                          )  # raise ValueError if not found
                      except ValueError:
                          raise ValueError(
                              "{} not found in new class names {}".format(
                                  k, self.classes
                              )
                          )
                      reuse_weights.pop(k)
                      reuse_weights[new_idx] = v
          else:
              new_map = {}
              for x in reuse_weights:
                  try:
                      new_idx = self.classes.index(x)
                      old_idx = old_classes.index(x)
                      new_map[new_idx] = old_idx
                  except ValueError:
                      warnings.warn(
                          "{} not found in old: {} or new class names: {}".format(
                              x, old_classes, self.classes
                          )
                      )
              reuse_weights = new_map
      with self.name_scope():
          old_mask = self.mask
          ctx = list(old_mask.params.values())[0].list_ctx()
          # to avoid deferred init, number of in_channels must be defined
          in_channels = list(old_mask.params.values())[0].shape[1]
          init = mx.init.Xavier(
              rnd_type="gaussian", factor_type="out", magnitude=2
          )
          self.mask = nn.Conv2D(
              len(classes),
              kernel_size=(1, 1),
              strides=(1, 1),
              padding=(0, 0),
              weight_initializer=init,
              in_channels=in_channels,
          )
          self.mask.initialize(ctx=ctx)
          if reuse_weights:
              assert isinstance(reuse_weights, dict)
              for old_params, new_params in zip(
                  old_mask.params.values(), self.mask.params.values()
              ):
                  # slice and copy weights
                  old_data = old_params.data()
                  new_data = new_params.data()
  
                  for k, v in reuse_weights.items():
                      if k >= len(self.classes) or v >= len(
                          old_classes
                      ):
                          warnings.warn(
                              "reuse mapping {}/{} -> {}/{} out of range".format(
                                  k, self.classes, v, old_classes
                              )
                          )
                          continue
                      new_data[k : k + 1] = old_data[v : v + 1]
                  # set data to new conv layers
                  new_params.set_data(new_data)
  
imports: from __future__ import absolute_import
  import os
  import warnings
  import mxnet
  from mxnet import autograd
  from mxnet.gluon import nn
  from mxnet.gluon.contrib.nn import SyncBatchNorm
  from .rcnn_target import MaskTargetGenerator
  from ..faster_rcnn import FasterRCNN
  from ..rcnn import custom_rcnn_fpn
label_desc: Use image node_id 3 for calling the Mask obj's underlying member method code with example usage: obj.reset_class(classes, reuse_weights) without return types