Skip to content

Instantly share code, notes, and snippets.

View pranjalAI's full-sized avatar

Pranjal Saxena pranjalAI

View GitHub Profile
for _ in range(10):
try:
states_values = enc_model.predict( str_to_tokens( input( 'Enter question : ' ) ) )
empty_target_seq = np.zeros( ( 1 , 1 ) )
empty_target_seq[0, 0] = tokenizer.word_index['start']
stop_condition = False
decoded_translation = ''
while not stop_condition :
dec_outputs , h , c = dec_model.predict([ empty_target_seq ] + states_values )
sampled_word_index = np.argmax( dec_outputs[0, -1, :] )
import os, random, shutil
import numpy as np
import pandas as pd
import PIL
#import keras
import itertools
from PIL import Image
import tensorflow as tf
datagen = ImageDataGenerator(rescale=1.0/255.0)
train_path = 'Your Image Folder Path'
train_batches = datagen.flow_from_directory(train_path, target_size=(200,200), classes=classes_required, batch_size=batch_size_train)
model=Sequential()
model.add(Conv2D(16,kernel_size=(3,3), activation="relu" ,input_shape=IMAGE_SIZE + [3], padding='same'))
model.add(Conv2D(32, kernel_size=(3,3), activation="relu",padding='same'))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Dropout(0.30))
model.add(Conv2D(64, kernel_size=(3,3), activation="relu",padding='same'))
#model.add(BatchNormalization())
test_image=cv2.imread("IMAGE_PATH")
test_image = np.expand_dims(test_image, axis=0)
out=np.argmax(model_loaded.predict(test_image))
Ans=np.where(out==0, "Middle",
(np.where(out==1,"Old",
"Young"))).item()
print(Ans+" age person.")
# Importing Libraries
import os
import numpy as np
import cv2
import argparse
import time
from tqdm import tqdm
#convert from Yolo_mark to opencv format
def yoloFormattocv(x1, y1, x2, y2, H, W):
bbox_width = x2 * W
# Convert from opencv format to yolo format
# H,W is the image height and width
def cvFormattoYolo(corner, H, W):
bbox_W = corner[3] - corner[1]
bbox_H = corner[4] - corner[2]
center_bbox_x = (corner[1] + corner[3]) / 2
center_bbox_y = (corner[2] + corner[4]) / 2
return corner[0], round(center_bbox_x / W, 6),
round(center_bbox_y / H, 6),
round(bbox_W / W, 6),
class yoloRotatebbox:
def __init__(self, filename, image_ext, angle):
assert os.path.isfile(filename + image_ext)
assert os.path.isfile(filename + '.txt')
self.filename = filename
self.image_ext = image_ext
self.angle = angle
# Read image using cv2
if __name__ == "__main__":
angels=[45,90,135,180,225,270,315]
for filename in tqdm(os.listdir()):
file =filename.split(".")
if(file[-1]=="jpg"):
image_name=file[0]
image_ext="."+file[1]
else:
continue
for angle in angels:
from google.colab import drive
drive.mount('/content/gdrive')
!ln -s /content/gdrive/My\ Drive/ /mydrive
!ls /mydrive