import strengthen_functions parser = argparse.ArgumentParser() parser.add_argument('-n', action="store", dest="number") parser.add_argument('-i', action="store", dest="iterations", default=80000, help="default: 30000") args = parser.parse_args() number = int(args.number) iterations = int(args.iterations) pf = strengthen_functions.PF81 nn = NeuralNetwork(strength_function=pf, image_scale=8, transmission_history_len=10**4) ''' train_imgs, _ = skl.load_data() train_imgs = train_imgs[number] size = len(train_imgs) ''' # average_img = skl.average_img_by_number(number) train_imgs = skl.get_imgs_by_number(number) plotting_strength = True if plotting_strength: strength_stats = [] start_time = datetime.datetime.now() for i in range(iterations): _, img = random.choice(train_imgs)
# import seaborn as sns # import sys import random iters = 5 * 10**4 imgs_l = [skl.get_imgs_by_number(i) for i in range(10)] strength_matrix_l = [ utils.read_pickle('pkl/nn_growable_' + str(i) + '.pkl') for i in range(10) ] fig, axes = plt.subplots(2, 2, figsize=(10, 5), sharex=True, sharey=False) axes = axes.flatten() pfs = [ lambda img, matrix: NeuralNetwork.validate_linear( img, matrix, gray_max=16, power=0, weight=10), lambda img, matrix: NeuralNetwork.validate_linear( img, matrix, gray_max=16, power=1, weight=10), lambda img, matrix: NeuralNetwork.validate_linear( img, matrix, gray_max=16, power=3, weight=10), lambda img, matrix: NeuralNetwork.validate_threshold( img, matrix, gray_max=16, power=3, threshhold=.2, weight=10) ] # if True: # for j, matrix in enumerate(strength_matrix_l): for k, pf in enumerate(pfs): j = 6 matrix = strength_matrix_l[j] results_l = [[], [], [], [], [], [], [], [], [], []] for imgs, result in zip(imgs_l, results_l):
strength_matrix_l = [ utils.read_pickle('pkl/nn_growable_' + str(i) + '.pkl') for i in range(10) ] fig, axes = plt.subplots(5, 2, figsize=(3, 6), sharex=True, sharey=True) axes = axes.flatten() for j, matrix in enumerate(strength_matrix_l): results_l = [[], [], [], [], [], [], [], [], [], []] for imgs, result in zip(imgs_l, results_l): for i in range(iters): img = random.choice(imgs)[1] result.append( NeuralNetwork.validate_1(img, matrix, gray_max=16, threshhold=.6, weight=3)) for i, result in enumerate(results_l): if i != j: color = 'gray' zorder = 0 line = 1 else: color = 'red' zorder = 1 line = 2 mu = np.mean(result) std = np.std(result) # sns.kdeplot(result, color=color, shade=False, shade_lowest=False, alpha=1, zorder=zorder)
import random random.seed() iters = 10 * 10 ** 4 num = 0 imgs_l = [skl.get_imgs_by_number(i) for i in range(10)] strength_matrix_l = [utils.read_pickle('pkl/nn_growable_' + str(i) + '.pkl') for i in range(10)] # fig, axes = plt.subplots(4, 1, figsize=(6, 6), sharex=True, sharey=False) fig, axes = plt.subplots(3, 1, figsize=(6, 4), sharex=True, sharey=False) axes = axes.flatten() validators = [ lambda img, matrix: NeuralNetwork.validate_original(img, matrix), lambda img, matrix: NeuralNetwork.validate_step(img, matrix, threshold=.6), lambda img, matrix: NeuralNetwork.validate_linear(img, matrix, power=3, weight=10)] # lambda img, matrix: NeuralNetwork.validate_threshold(img, matrix, power=3, threshhold=.2, weight=10)] imgs = imgs_l[num] for k, vldt in enumerate(validators): matrix = strength_matrix_l[num] results_l = [[], [], [], [], [], [], [], [], [], []] for matrix, result in zip(strength_matrix_l, results_l): for i in range(iters): img = random.choice(imgs)[1] result.append(vldt(img, matrix)) # get the mu and std for z-scores results_l_part = [i for i in results_l if i != num]
imgs_l = [skl.get_imgs_by_number(i) for i in range(10)] matrix_80_l = [ utils.read_pickle('pkl/nn_growable_80_' + str(i) + '.pkl') for i in range(10) ] matrix_81_l = [ utils.read_pickle('pkl/nn_growable_81_' + str(i) + '.pkl') for i in range(10) ] # fig, axes = plt.subplots(4, 1, figsize=(6, 6), sharex=True, sharey=False) fig, axes = plt.subplots(3, 1, figsize=(6, 4), sharex=True, sharey=False) axes = axes.flatten() validators = [ lambda img, matrix: NeuralNetwork.validate_original(img, matrix), lambda img, matrix: NeuralNetwork.validate_original(img, matrix), # lambda img, matrix: NeuralNetwork.validate_step(img, matrix, threshold=.6), lambda img, matrix: NeuralNetwork.validate_linear( img, matrix, power=3, weight=100) ] # lambda img, matrix: NeuralNetwork.validate_threshold(img, matrix, power=3, threshhold=.2, weight=10)] imgs = imgs_l[num] for k, (vldt, matrix_l) in enumerate( zip(validators, (matrix_81_l, matrix_80_l, matrix_81_l))): matrix = matrix_l[num] results_l = [[], [], [], [], [], [], [], [], [], []] for matrix, result in zip(matrix_l, results_l): for i in range(iters): img = random.choice(imgs)[1]