def main(dataset="babl"): if dataset == "nlvr": data = prepare.load_data(train_json) data = prepare.tokenize_data(data, mxlen) imgs, ws, labels = prepare.load_images(train_img_folder, data, debug=True) data.clear() imgs_mean = np.mean(imgs) imgs_std = np.std(imgs - imgs_mean) imgs = (imgs - imgs_mean) / imgs_std else: inputs_train, queries_train, answers_train, inputs_test, queries_test, answers_test = prepare.get_babl_data( ) epochs = 100 model = build_model.model() model.fit([inputs_train, queries_train], answers_train, validation_split=0.1, epochs=epochs) model.save('model')
from keras.optimizers import Adam import gc import prepare import subprocess mxlen = 32 embedding_dim = 50 lstm_unit = 128 MLP_unit = 128 epochs = 100 train_json = 'nlvr\\train\\train.json' train_img_folder = 'nlvr\\train\\images' data = prepare.load_data(train_json) data = prepare.tokenize_data(data, mxlen) imgs, ws, labels = prepare.load_images(train_img_folder, data, debug=True) data.clear() imgs_mean = np.mean(imgs) imgs_std = np.std(imgs - imgs_mean) imgs = (imgs - imgs_mean) / imgs_std epochs = 100 batch_size = 64 def bn_layer(x, conv_unit): def f(inputs): md = Conv2D(x, (conv_unit, conv_unit), padding='same')(inputs) md = BatchNormalization()(md) return Activation('relu')(md) return f
mxlen, seed) EPOCHS = 60 BATCH_SIZE = 256 train_json = 'data/nlvr/train/train.json' train_img_folder = 'data/nlvr/train/images' dev_json = 'data/nlvr/dev/dev.json' dev_img_folder = 'data/nlvr/dev/images' print('Processing input data...') data = prepare.load_data(train_json) prepare.init_tokenizer(data) data = prepare.tokenize_data(data, mxlen) imgs, ws, labels = prepare.load_images(train_img_folder, data, section=True) data.clear() dev_data = prepare.load_data(dev_json) dev_data = prepare.tokenize_data(dev_data, mxlen) dev_imgs, dev_ws, dev_labels = prepare.load_images(dev_img_folder, dev_data, section=True) dev_data.clear() imgs_mean = np.mean(imgs) imgs_std = np.std(imgs - imgs_mean) imgs = (imgs - imgs_mean) / (imgs_std + 1e-7) dev_imgs = (dev_imgs - imgs_mean) / (imgs_std + 1e-7) imgs_1, imgs_2, imgs_3 = imgs[:,0,:,:], imgs[:,1,:,:], imgs[:,2,:,:] dev_imgs_1, dev_imgs_2, dev_imgs_3 = dev_imgs[:,0,:,:], dev_imgs[:,1,:,:], dev_imgs[:,2,:,:]
mxlen = 32 embedding_dim = 50 lstm_unit = 64 MLP_unit = 128 epochs = 200 batch_size = 256 l2_norm = 1e-4 train_json = 'nlvr\\train\\train.json' train_img_folder = 'nlvr\\train\\images' test_json = 'nlvr\\dev\\dev.json' test_img_folder = 'nlvr\\dev\\images' data = prepare.load_data(train_json) prepare.init_tokenizer(data) data = prepare.tokenize_data(data, mxlen) imgs, ws, labels = prepare.load_images(train_img_folder, data) data.clear() test_data = prepare.load_data(test_json) test_data = prepare.tokenize_data(test_data, mxlen) test_imgs, test_ws, test_labels = prepare.load_images(test_img_folder, test_data) test_data.clear() imgs_mean = np.mean(imgs) imgs_std = np.std(imgs - imgs_mean) imgs = (imgs - imgs_mean) / imgs_std test_imgs = (test_imgs - imgs_mean) / imgs_std def bn_layer(x, conv_unit):
import numpy as np import matplotlib.pyplot as plt import prepare, align, classify, present CLSNAMES = ['phnat', 'bualex'] CLSCOUNT = len(CLSNAMES) # compose a video path for each classname VIDPATHS = ['./data/vid' + n + '.mp4' for n in range(CLSCOUNT)] images = [prepare.load_images(VIDPATHS[n]) for n in range(CLSCOUNT)] X = [] y = [] for i in range(CLSCOUNT): for img in images[i]: X.append(img) y.append(i) X = np.asarray(X) print "composed X matrix. Shape:", X.shape, "y shape:", y.shape X_f = align.frontalize(X) print "perormed frontalzation." present.two_img(X[1], X_f[1]) net = classify.DeepRtlNet()