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
#Write a function to choose one image randomly from your dataset and predict using Trained model. | |
def show_image_with_predictions(df, threshold=0.6): | |
# choose a random image | |
row = df.sample() | |
filepath = row['fileName'].values[0] | |
print("filepath:", filepath) | |
# get all rows for this image | |
df2 = df[df['fileName'] == filepath] | |
im = np.array(Image.open(filepath)) |
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 glob import glob | |
model_paths = glob('snapshots/resnet50_csv_0*.h5') | |
latest_path = sorted(model_paths)[-1] | |
print("path:", latest_path) | |
from keras_retinanet import models | |
model = models.load_model(latest_path, backbone_name='resnet50') | |
model = models.convert_model(model) |
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
python keras_retinanet/bin/train.py --freeze-backbone | |
--random-transform \ | |
--weights {PRETRAINED_MODEL} | |
--batch-size 8 | |
--steps 500 | |
--epochs 15 | |
csv maskDetectorData.csv maskDetectorClasses.csv |
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
#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 |
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
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) | |
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
#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') |
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
# 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] |
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
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 |
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
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 |
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
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 |
NewerOlder