def LoadPretrained(self, param):
    node1_name = param.pretrained_model_node1
    node2_name = param.pretrained_model_node2
    if node1_name == '':
      node1_name = self.proto.node1
    if node2_name == '':
      node2_name = self.proto.node2

    if param.transpose_pretrained:
      temp = node1_name
      node1_name = node2_name
      node2_name = temp
    mat = None
    for pretrained_model in param.pretrained_model:
      model_file = os.path.join(self.prefix, pretrained_model)
      ext = os.path.splitext(pretrained_model)[1]
      if ext == '.npz':
        npzfile = np.load(model_file)
        if param.name == 'bias':
          this_mat = np.nan_to_num(npzfile['mean'] / npzfile['std'])
        elif param.name == 'precision':
          this_mat = np.nan_to_num(1. / npzfile['std'])
      elif ext == '.npy':
        this_mat = np.load(model_file)
      else:
        model = util.ReadModel(model_file)
        try:
          edge = next(e for e in model.edge if e.node1 == node1_name and e.node2 == node2_name)
        except StopIteration as e:
          print 'No edge found between %s and %s in model %s.' % (node1_name, node2_name, model_file)
          raise e
        pretrained_param = next(p for p in edge.param if p.name == param.name)
        assert pretrained_param.mat != '',\
                'Pretrained param %s in edge %s:%s of model %s is empty!!' % (
                  pretrained_param.name, edge.node1, edge.node2, pretrained_model)
        if param.transpose_pretrained:
          assert param.dimensions == pretrained_param.dimensions[::-1],\
              'Param has shape %s but transposed pretrained param has shape %s' % (
                param.dimensions, reversed(pretrained_param.dimensions))
        else:
          assert param.dimensions == pretrained_param.dimensions,\
              'Param has shape %s but pretrained param has shape %s' % (
                param.dimensions, pretrained_param.dimensions)
        this_mat = param.mult_factor * util.ParameterAsNumpy(pretrained_param)
      if param.transpose_pretrained:
        this_mat = this_mat.T
      if mat is None:
        mat = this_mat
      else:
        mat += this_mat
    return mat / len(param.pretrained_model)
dataset/ETHPy150Open nitishsrivastava/deepnet/deepnet/edge.py/Edge.LoadPretrained/original