Skip to content

Instantly share code, notes, and snippets.

View Shreyz-max's full-sized avatar
💻
Experimenting

Shreya Shreyz-max

💻
Experimenting
  • India
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Shreyz-max
Shreyz-max / custom_generator.py
Created March 15, 2021 11:29
loading data using custom generator
def load_datatest(train_path, epochs=100, x_data=x_data, tokenizer=tokenizer, num_decoder_tokens=1500,training_list=train_list, batch_size=32, maxlen=10):
encoder_input_data = []
decoder_input_data = []
decoder_target_data = []
videoId = []
videoSeq = []
# separating the videoId and the video captions
for idx, cap in enumerate(training_list):
caption = cap[0]
videoId.append(cap[1])
@Shreyz-max
Shreyz-max / training_model.py
Created March 15, 2021 11:25
training model description
"""
time_steps_encoder is the number of frames per video we will be using for training
num_encoder_tokens is the number of features from each frame
latent_dim is the number of hidden features for lstm
time_steps_decoder is the maximum length of each sentence
num_decoder_tokens is the final number of tokens in the softmax layer
batch size
"""
time_steps_encoder=80
num_encoder_tokens=4096
@Shreyz-max
Shreyz-max / clean_captions.py
Last active March 15, 2021 11:17
cleaning captions
train_path='training_data'
TRAIN_LABEL_PATH = os.path.join(train_path, 'training_label.json')
# mentioning the train test split
train_split = 0.85
# loading the json file for training
with open(TRAIN_LABEL_PATH) as data_file:
y_data = json.load(data_file)
# train_list contains all the captions with their video ID
# vocab_list contains all the vocabulary from training data
train_list = []
@Shreyz-max
Shreyz-max / extract_features.py
Created March 15, 2021 10:55
extract features
def model_cnn_load():
model = VGG16(weights="imagenet", include_top=True, input_shape=(224, 224, 3))
out = model.layers[-2].output
model_final = Model(inputs=model.input, outputs=out)
return model_final
def load_image(path):
img = cv2.imread(path)
img = cv2.resize(img, (224, 224))
@Shreyz-max
Shreyz-max / extract_images.py
Created March 15, 2021 10:44
extract images
def video_to_frames(video):
path = os.path.join(config.test_path, 'temporary_images')
if os.path.exists(path):
shutil.rmtree(path)
os.makedirs(path)
video_path = os.path.join(config.test_path, 'video', video)
count = 0
image_list = []
# Path to video file
cap = cv2.VideoCapture(video_path)