Args:
        name(str):
        val(np.ndarray): 4D tensor of NHWC. assume RGB if C==3.
            Can be either float or uint8. Range has to be [0,255].

    Returns:
        tf.Summary:
349185
def create_image_summary(name, val):
    
    assert isinstance(name, six.string_types), type(name)
    n, h, w, c = val.shape
    val = val.astype('uint8')
    s = tf.Summary()
    imparams = [cv2.IMWRITE_PNG_COMPRESSION, 9]
    for k in range(n):
        arr = val[k]
        # CV2 will only write correctly in BGR chanel order
        if c == 3:
            arr = cv2.cvtColor(arr, cv2.COLOR_RGB2BGR)
        elif c == 4:
            arr = cv2.cvtColor(arr, cv2.COLOR_RGBA2BGRA)
        tag = name if n == 1 else '{}/{}'.format(name, k)
        retval, img_str = cv2.imencode('.png', arr, imparams)
        if not retval:
            # Encoding has failed.
            continue
        img_str = img_str.tostring()

        img = tf.Summary.Image()
        img.height = h
        img.width = w
        # 1 - grayscale 3 - RGB 4 - RGBA
        img.colorspace = c
        img.encoded_image_string = img_str
        s.value.add(tag=tag, image=img)
    return s
797504
def new_prelu(self, name: str, input_layer_name: str=None):
        
        input_layer = self.__network.get_layer(input_layer_name)

        with tf.variable_scope(name):
            channels_input = int(input_layer.get_shape()[-1])
            alpha = self.__make_var('alpha', shape=[channels_input])
            output = tf.nn.relu(input_layer) + tf.multiply(alpha, -tf.nn.relu(-input_layer))

        self.__network.add_layer(name, layer_output=output)
645939
public SDVariable layerNorm(String name, SDVariable input, SDVariable gain, SDVariable bias, int... dimensions) {
        validateFloatingPoint("layerNorm", "input", input);
        validateFloatingPoint("layerNorm", "gain", gain);
        validateFloatingPoint("layerNorm", "bias", bias);
        SDVariable result = f().layerNorm(input, gain, bias, dimensions);
        return updateVariableNameAndReference(result, name);
    }
845519
def fcast(value: float) -> TensorLike:
    """"""
    newvalue = tf.cast(value, FTYPE)
    if DEVICE == 'gpu':
        newvalue = newvalue.gpu()  # Why is this needed?  # pragma: no cover
    return newvalue
1021198
def recognize_ndarray(self, ndarray):
        
        if self._recognize_raw_image_func is None:
            raise RuntimeError('NumPy missing')
        height, width = ndarray.shape[:2]
        bpp = ndarray.shape[2] if len(ndarray.shape) > 2 else 1
        ptr = self._recognize_raw_image_func(self.alpr_pointer, ndarray.flatten(), bpp, width, height)
        json_data = ctypes.cast(ptr, ctypes.c_char_p).value
        json_data = _convert_from_charp(json_data)
        
        # there is a bug in the openalpr python bindings
        # sometimes there are real numbers with "," as the decimal point..!
        # print("openalpr_lib : recognize_ndarray : json_data =", json_data)
        p = re.compile('\d(\,)\d')
        json_data = p.subn(".", json_data)[0]
        
        response_obj = json.loads(json_data)
        self._free_json_mem_func(ctypes.c_void_p(ptr))
        return response_obj
1128196
def create_scalar_summary(name, v):
    
    assert isinstance(name, six.string_types), type(name)
    v = float(v)
    s = tf.Summary()
    s.value.add(tag=name, simple_value=v)
    return s
891290
def get_variable(self, name):
        
        name = get_op_tensor_name(name)[1]
        if len(self.vs_name):
            name_with_vs = self.vs_name + "/" + name
        else:
            name_with_vs = name
        return get_op_or_tensor_by_name(name_with_vs)
854566
def RGB(self, val):
        """"""
        # need to convert to normalized float
        val = np.atleast_1d(val).astype(np.float32) / 255.
        self.rgba = val
467710
def create_visual_input(camera_parameters, name):
        
        o_size_h = camera_parameters['height']
        o_size_w = camera_parameters['width']
        bw = camera_parameters['blackAndWhite']

        if bw:
            c_channels = 1
        else:
            c_channels = 3

        visual_in = tf.placeholder(shape=[None, o_size_h, o_size_w, c_channels], dtype=tf.float32,
                                   name=name)
        return visual_in
106274
def _check_color_dim(val):
    """"""
    val = np.atleast_2d(val)
    if val.shape[1] not in (3, 4):
        raise RuntimeError('Value must have second dimension of size 3 or 4')
    return val, val.shape[1]
895764
def transpose(self, name=None):
    
    if name is None:
      name = self.module_name + "_transpose"

    if self._data_format == DATA_FORMAT_NWC:
      stride = self._stride[1:-1]
    else:  # self._data_format == DATA_FORMAT_NCW
      stride = self._stride[2:]

    return Conv1D(output_channels=lambda: self.input_channels,
                  kernel_shape=self.kernel_shape,
                  stride=stride,
                  padding=self.padding,
                  use_bias=self._use_bias,
                  initializers=self.initializers,
                  partitioners=self.partitioners,
                  regularizers=self.regularizers,
                  data_format=self._data_format,
                  custom_getter=self._custom_getter,
                  name=name)
313449
def _check_var(var, dtype, ndmin, name, shape=None, shape2=None):
    """
    if var is None:
        raise ValueError
    var = np.array(var, dtype=dtype, copy=True, ndmin=ndmin)
    if shape:
        _check_shape(var, name, shape, shape2)
    return var
1011261
def get(self, name: str, default: Any = None) -> np.ndarray:
		
		if name in self:
			return self[name]
		else:
			return default
886471
def obfn_gvar(self):
        

        if self.opt['gEvalY']:
            return self.Y
        else:
            return self.cnst_A(None, self.Xf) - self.cnst_c()
712081
def set_val(self, nval):
        
        file_obj = file(os.path.join(self._base, self._attr), 'w')
        try:
            file_obj.write(str(nval) + '\n')
        finally:
            file_obj.close()
261693
def generate_scalar_constant(output_name, tensor_name, scalar):
    """"""
    t = onnx.helper.make_tensor(tensor_name,
                                data_type=TensorProto.FLOAT,
                                dims=[1], vals=[scalar])
    c = onnx.helper.make_node("Constant",
                              [],
                              [output_name],
                              value=t)
    return c
260715
def visual(title, X, name):
    
    assert len(X.shape) == 4
    X = X.transpose((0, 2, 3, 1))
    X = np.clip((X - np.min(X))*(255.0/(np.max(X) - np.min(X))), 0, 255).astype(np.uint8)
    n = np.ceil(np.sqrt(X.shape[0]))
    buff = np.zeros((int(n*X.shape[1]), int(n*X.shape[2]), int(X.shape[3])), dtype=np.uint8)
    for i, img in enumerate(X):
        fill_buf(buff, i, img, X.shape[1:3])
    buff = buff[:, :, ::-1]
    plt.imshow(buff)
    plt.title(title)
    plt.savefig(name)