|
| 1 | +from tflearn import input_data, conv_2d, max_pool_2d, fully_connected, dropout, Momentum, regression, DNN |
| 2 | + |
| 3 | +#model of vgg-19 |
| 4 | +def vgg_net_19(width, height): |
| 5 | + network = input_data(shape=[None, height, width, 3], name='input') |
| 6 | + network = conv_2d(network, 64, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 7 | + network = conv_2d(network, 64, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 8 | + network = max_pool_2d(network, 2, strides=2) |
| 9 | + network = conv_2d(network, 128, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 10 | + network = conv_2d(network, 128, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 11 | + network = max_pool_2d(network, 2, strides=2) |
| 12 | + network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 13 | + network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 14 | + network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 15 | + network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 16 | + network = max_pool_2d(network, 2, strides=2) |
| 17 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 18 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 19 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 20 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 21 | + network = max_pool_2d(network, 2, strides=2) |
| 22 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 23 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 24 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 25 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 26 | + network = max_pool_2d(network, 2, strides=2) |
| 27 | + network = fully_connected(network, 4096, activation='relu', weight_decay=5e-4) |
| 28 | + network = dropout(network, keep_prob=0.5) |
| 29 | + network = fully_connected(network, 4096, activation='relu', weight_decay=5e-4) |
| 30 | + network = dropout(network, keep_prob=0.5) |
| 31 | + network = fully_connected(network, 1000, activation='softmax', weight_decay=5e-4) |
| 32 | + |
| 33 | + opt = Momentum(learning_rate=0, momentum = 0.9) |
| 34 | + network = regression(network, optimizer=opt, loss='categorical_crossentropy', name='targets') |
| 35 | + |
| 36 | + model = DNN(network, checkpoint_path='', max_checkpoints=1, tensorboard_verbose=2, tensorboard_dir='') |
| 37 | + |
| 38 | + return model |
| 39 | + |
| 40 | +#model of vgg-19 for testing of the activations |
| 41 | +#rename the output you want to test, connect it to the next layer and change the output layer at the bottom (model = DNN(...)) |
| 42 | +#make sure to use the correct test function (depending if your output is a tensor or a vector) |
| 43 | +def vgg_net_19_activations(width, height): |
| 44 | + network = input_data(shape=[None, height, width, 3], name='input') |
| 45 | + network1 = conv_2d(network, 64, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 46 | + network2 = conv_2d(network1, 64, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 47 | + network = max_pool_2d(network2, 2, strides=2) |
| 48 | + network = conv_2d(network, 128, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 49 | + network = conv_2d(network, 128, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 50 | + network = max_pool_2d(network, 2, strides=2) |
| 51 | + network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 52 | + network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 53 | + network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 54 | + network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 55 | + network = max_pool_2d(network, 2, strides=2) |
| 56 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 57 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 58 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 59 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 60 | + network = max_pool_2d(network, 2, strides=2) |
| 61 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 62 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 63 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 64 | + network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4) |
| 65 | + network = max_pool_2d(network, 2, strides=2) |
| 66 | + network = fully_connected(network, 4096, activation='relu', weight_decay=5e-4) |
| 67 | + network = dropout(network, keep_prob=0.5) |
| 68 | + network = fully_connected(network, 4096, activation='relu', weight_decay=5e-4) |
| 69 | + network = dropout(network, keep_prob=0.5) |
| 70 | + network = fully_connected(network, 1000, activation='softmax', weight_decay=5e-4) |
| 71 | + |
| 72 | + opt = Momentum(learning_rate=0, momentum = 0.9) |
| 73 | + network = regression(network, optimizer=opt, loss='categorical_crossentropy', name='targets') |
| 74 | + |
| 75 | + model = DNN(network1, checkpoint_path='', max_checkpoints=1, tensorboard_verbose=2, tensorboard_dir='') |
| 76 | + |
| 77 | + return model |
0 commit comments