Skip to content

Instantly share code, notes, and snippets.

View Praveen76's full-sized avatar
🎯
Focusing

Praveen Kumar Anwla Praveen76

🎯
Focusing
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import os
print(os.getcwd())
git clone https://github.com/fizyr/keras-retinanet.git
%cd keras-retinanet/
!pip install .
!python setup.py build_ext --inplace
import os
print(os.getcwd())
git clone https://github.com/fizyr/keras-retinanet.git
%cd keras-retinanet/
!pip install .
!python setup.py build_ext --inplace
import numpy as np
import shutil
import pandas as pd
import os, sys, random
import xml.etree.ElementTree as ET
import pandas as pd
from os import listdir
from os.path import isfile, join
import matplotlib.pyplot as plt
from PIL import Image
pngPath='C:/Users/PraveenKumar/RetinaNet//maskDetectorJPEGImages/'
annotPath='C:/Users/PraveenKumar/RetinaNet//maskDetectorXMLfiles/'
data=pd.DataFrame(columns=['fileName','xmin','ymin','xmax','ymax','class'])
os.getcwd()
#read All files
allfiles = [f for f in listdir(annotPath) if isfile(join(annotPath, f))]
#Read all pdf files in images and then in text and store that in temp folder
# pick a random image
filepath = df.sample()['fileName'].values[0]
# get all rows for this image
df2 = df[df['fileName'] == filepath]
im = np.array(Image.open(filepath))
# if there's a PNG it will have alpha channel
im = im[:,:,:3]
#Define labels & write them in a file
classes = ['mask','noMask']
with open('../maskDetectorClasses.csv', 'w') as f:
for i, class_name in enumerate(classes):
f.write(f'{class_name},{i}\n')
if not os.path.exists('snapshots'):
os.mkdir('snapshots')
URL_MODEL = 'https://github.com/fizyr/keras-retinanet/releases/download/0.5.1/resnet50_coco_best_v2.1.0.h5'
urllib.request.urlretrieve(URL_MODEL, PRETRAINED_MODEL)
#Put your training data path & file that has labels for your training data
!keras_retinanet/bin/train.py
--freeze-backbone
--random-transform
--weights {PRETRAINED_MODEL}
--batch-size 8
--steps 500
--epochs 15
csv maskDetectorData.csv
maskDetectorClasses.csv