Skip to content

Instantly share code, notes, and snippets.

View ashhadulislam's full-sized avatar

Ashhad ashhadulislam

View GitHub Profile
while 1==1:
out = kinesis.get_records(shard_it, limit=1)
shard_it = out["NextShardIterator"]
if len(out["Records"])>0:
print(out["Records"][0]["Data"])
time.sleep(0.3)
from boto import kinesis
import time
kinesis = kinesis.connect_to_region("us-east-2")
shard_id = 'shardId-000000000000' #we only have one shard!
shard_it = kinesis.get_shard_iterator("end-stream", shard_id, "LATEST")["ShardIterator"]
while 1==1:
out = kinesis.get_records(shard_it, limit=1)
shard_it = out["NextShardIterator"]
# print(out)
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from bs4 import BeautifulSoup
import pandas as pd
import os
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.select import Select
import pickle
chrome_options = Options()
# chrome_options.add_argument("--headless")
# above should be uncommented if you are
# running the code in a machine without GUI
chromedriver_loc = 'software/chromedriver'
browser = webdriver.Chrome(executable_path=chromedriver_loc, chrome_options=chrome_options)
import cv2
import matplotlib.pyplot as plt
import os, shutil
img=cv2.imread("raw_yolo_keras/train/001446_jpg.rf.00a11ab7cffb0a8fec57e98b2c4663d5.jpg")
crop_img = img[ 318:373, 216:265]
fig,axs=plt.subplots(1,2)
axs[0].imshow(img)
axs[1].imshow(crop_img)
import cv2
import matplotlib.pyplot as plt
import os, shutil
#create a folder to store the images of heads with and without helmets
if os.path.isdir("raw_yolo_keras/train/yes_helmet"):
shutil.rmtree("raw_yolo_keras/train/yes_helmet")
os.mkdir("raw_yolo_keras/train/yes_helmet")
import tensorflow as tf
import os
import cv2
import numpy as np
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Input, Dense, Dropout
from tensorflow.keras.callbacks import EarlyStopping, CSVLogger, ReduceLROnPlateau
from sklearn.model_selection import train_test_split
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.inception_resnet_v2 import preprocess_input, decode_predictions
def load_data(path):
x_train = []
y_train = []
yes_helmet_location=os.path.join(location,"yes_helmet")
no_helmet_location=os.path.join(location,"no_helmet")
yes_helmet_files=os.listdir(yes_helmet_location)
no_helmet_files=os.listdir(no_helmet_location)
for ffile in yes_helmet_files[:5000]:
img=cv2.imread(os.path.join(yes_helmet_location,ffile))
import tensorflow as tf
import numpy as np
from tensorflow.keras import models
from tensorflow.keras import Model
from tensorflow.keras.models import load_model
import matplotlib.pyplot as plt
import os
import tensorflow
import keras
import cv2
# read the saved model
def setup_hard_hat_detector():
return load_model("res/vgg16_model/ninety2_percent_just_vgg16.h5")
hh_model=setup_hard_hat_detector()
location="raw_yolo_keras/end_end_test"
#location where the images downloaded from the internet are placed
dim=(76,76)