def test(): """ Execute the tests Returns: (n_total, n_success) """ logger = TestLogger(TESTNAME) # load net and the data model = GoldenModel(CONFIG_FILENAME, NET_FILENAME, no_scale_between_l1_l2=True) data = dict(np.load(DATA_FILENAME)) net = dict(np.load(NET_FILENAME)) for i, layer in enumerate(model.layers): result = test_layer(layer, data) test_index = i + 2 if i == 0: test_index = "1+2" logger.show_subcase_result("Layer {}".format(test_index), result) result = test_model(model, data) logger.show_subcase_result("Model", result) # return summary return logger.summary()
def gen_stimuli(): """ This function generates the stimuli (input and output) for the test """ model = GoldenModel(CONFIG_FILENAME, NET_FILENAME, clip_balanced=False) x = np.random.randint(-60, 60, (model.F2, model.T // 8)).astype(int) x_align = align_array(x) y_exp = np.transpose(x) y_exp_align = np.transpose(x_align) y_exp_align = align_array(y_exp_align) return x, x_align, y_exp, y_exp_align
def gen_stimuli(random_input): """ This function generates the stimuli (input and output) for the test """ model = GoldenModel(CONFIG_FILENAME, NET_FILENAME, clip_balanced=False) if random_input: x = np.random.randint(-60, 60, (model.C, model.T)) else: x = np.load(INPUT_FILENAME)["input"][0, :, :] x = F.quantize_to_int(x, model.input_scale) y_exp = model.layers[0](x) return x, y_exp
def gen_stimuli(random_input, no_div=False, pad_data=False): """ This function generates the stimuli (input and output) for the test """ if no_div: model = GoldenModel(CONFIG_FILENAME, NET_FILENAME, clip_balanced=False, no_scale_between_l1_l2=True) layer = model.layers[0] if random_input: x = np.random.randint(-60, 60, (model.C, model.T)) else: x = np.load(INPUT_FILENAME)["input"][0, :, :] x = F.quantize_to_int(x, layer.input_scale) y_exp = layer(x) else: model = GoldenModel(CONFIG_FILENAME, NET_FILENAME, clip_balanced=False) layer1 = model.layers[0] layer2 = model.layers[1] if random_input: x = np.random.randint(-60, 60, (model.C, model.T)) else: x = np.load(INPUT_FILENAME)["input"][0, :, :] x = F.quantize_to_int(x, layer1.input_scale) y_exp = layer2(layer1(x)) y_exp_align = align_array(y_exp) if pad_data: C, T = x.shape T_pad = T + 63 assert T_pad % 4 == 0 x_pad = np.zeros((C, T_pad), dtype=np.int) x_pad[:, 31:31 + T] = x return x, x_pad, y_exp, y_exp_align else: x_align = align_array(x) return x, x_align, y_exp, y_exp_align
def gen_stimuli(): """ This function generates the stimuli (input and output) for the test """ model = GoldenModel(CONFIG_FILENAME, NET_FILENAME, clip_balanced=False) x = np.random.randint(-60, 60, (model.F1, model.C, model.T)).astype(int) x_align = np.zeros( (model.F1, align_array_size(model.C), align_array_size(model.T))) x_align = x_align.astype(int) x_align[:, :model.C, :model.T] = x y_exp = np.transpose(x, (0, 2, 1)) y_exp_align = np.transpose(x_align, (0, 2, 1)) return x, x_align, y_exp, y_exp_align
def gen_stimuli(random_input): """ This function generates the stimuli (input and output) for the test """ model = GoldenModel(CONFIG_FILENAME, NET_FILENAME, clip_balanced=False) layer = model.layers[2] if random_input: x = np.random.randint(-60, 60, (model.F2, model.T // 8)) else: x = np.load(INPUT_FILENAME)["layer2_activ"][0, :, 0, :] x = F.quantize_to_int(x, layer.input_scale) y_exp = layer(x) x_align = align_array(x) y_exp_align = align_array(y_exp) return x, x_align, y_exp, y_exp_align
def gen_stimuli(random_input, flip, reorder_bn): """ This function generates the stimuli (input and output) for the test """ model = GoldenModel(CONFIG_FILENAME, NET_FILENAME, clip_balanced=False, reorder_bn=reorder_bn) layer = model.layers[1] if random_input: x = np.random.randint(-60, 60, (model.F1, model.C, model.T)) else: x = np.load(INPUT_FILENAME)["layer1_activ"][0, :, :, :] x = F.quantize_to_int(x, layer.input_scale) y_exp = layer(x) if flip: x_flip = np.transpose(x, (0, 2, 1)) x_align = np.zeros((model.F1, align_array_size(model.T), align_array_size(model.C)), dtype=int) x_align[:, :model.T, :model.C] = x_flip else: x_align = align_array(x) y_exp_align = align_array(y_exp) return x, x_align, y_exp, y_exp_align