def yolov2_image_coordinate(t_xy, t_wh, biases): import numpy as np from nnabla.parameter import pop_parameter, set_parameter h, w = t_xy.shape[-2:] xs = pop_parameter('xs') ys = pop_parameter('ys') if xs is None or (h != xs.shape[-1]): xs = nn.Variable.from_numpy_array(np.arange(w).reshape(1, 1, 1, -1)) xs.need_grad = False set_parameter('xs', xs) if ys is None or (h != ys.shape[-2]): ys = nn.Variable.from_numpy_array(np.arange(h).reshape(1, 1, -1, 1)) ys.need_grad = False set_parameter('ys', ys) t_x, t_y = F.split(t_xy, axis=2) oshape = list(t_x.shape) oshape.insert(2, 1) t_x = F.reshape((t_x + xs) / w, oshape) t_y = F.reshape((t_y + ys) / h, oshape) pop_parameter('biases') biases = biases.reshape(1, biases.shape[0], biases.shape[1], 1, 1) / np.array([w, h]).reshape(1, 1, 2, 1, 1) b = nn.Variable.from_numpy_array(biases) b.need_grad = False set_parameter('biases', b) t_wh = t_wh * b return t_x, t_y, t_wh
def test_get_set_pop_parameter(): import nnabla as nn from nnabla.parameter import set_parameter, pop_parameter, get_parameter nn.clear_parameters() x = nn.Variable((2, 3, 4, 5)) key = 'a/b/c' set_parameter(key, x) x2 = get_parameter(key) assert x is x2 x3 = pop_parameter(key) assert x is x3 x4 = get_parameter(key) assert x4 is None