Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
prajnasb authored Apr 3, 2020
1 parent 7136004 commit a01c2bf
Show file tree
Hide file tree
Showing 6 changed files with 2,775 additions and 0 deletions.
Binary file added mask_classifier/alarm.wav
Binary file not shown.
93 changes: 93 additions & 0 deletions mask_classifier/inference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env python
# coding: utf-8


#infrence code to detect font styles.



import torch
import torch.nn as nn
import torch.optim as optim
from torch.optim import lr_scheduler
import numpy as np
import torchvision
from torchvision import datasets, models, transforms
import matplotlib.pyplot as plt
import time
import os
import pandas as pd
from sklearn.model_selection import train_test_split
import shutil
import time
import copy
from PIL import Image
import glob


filepath = 'mask1_model_resnet50.pth'
model = torch.load(filepath)


class_names = ['with_mask',
'without_mask'
]



def process_image(image):
''' Scales, crops, and normalizes a PIL image for a PyTorch model,
returns an Numpy array
'''

# TODO: Process a PIL image for use in a PyTorch model
pil_image = Image.open(image)
#pil_image = image

image_transforms = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])

img = image_transforms(pil_image)
return img




def classify_face(image_path):
device = torch.device("cpu")
img = process_image(image_path)
print('image_processed')
img = img.unsqueeze_(0)
img = img.float()

model.eval()
model.cpu()
output = model(img)
print(output,'##############output###########')
_, predicted = torch.max(output, 1)
print(predicted.data[0],"predicted")


classification1 = predicted.data[0]
index = int(classification1)
print(class_names[index])
return class_names[index]

if __name__ == '__main__':
map_location=torch.device('cpu')
image_path = 'IMG20200402191409_02.jpg'
label = classify_face(image_path)
print("the label is", label)









98 changes: 98 additions & 0 deletions mask_classifier/label_detect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env python
# coding: utf-8




import torch
import torch.nn as nn
import torch.optim as optim
from torch.optim import lr_scheduler
import numpy as np
import torchvision
from torchvision import datasets, models, transforms
import matplotlib.pyplot as plt
import time
import os
import pandas as pd
from sklearn.model_selection import train_test_split
import shutil
import time
import copy
from PIL import Image
import glob
import cv2


filepath = 'mask1_model_resnet50.pth'
model = torch.load(filepath)


class_names = ['with_mask',
'without_mask'
]



def process_image(image):
''' Scales, crops, and normalizes a PIL image for a PyTorch model,
returns an Numpy array
'''

# TODO: Process a PIL image for use in a PyTorch model
#pil_image = Image.open(image)
pil_image = image

image_transforms = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])

img = image_transforms(pil_image)
return img




def classify_face(image):
device = torch.device("cpu")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
#im_pil = image.fromarray(image)
#image = np.asarray(im)
im = Image.fromarray(image)
image = process_image(im)
print('image_processed')
img = image.unsqueeze_(0)
img = image.float()

model.eval()
model.cpu()
output = model(image)
print(output,'##############output###########')
_, predicted = torch.max(output, 1)
print(predicted.data[0],"predicted")


classification1 = predicted.data[0]
index = int(classification1)
print(class_names[index])
return class_names[index]



if __name__ == '__main__':
#map_location=torch.device('cpu')
image = cv2.imread('praj.jpg')
label = classify_face(image)
print("the label is", label)









113 changes: 113 additions & 0 deletions mask_classifier/requirements.txt.
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
absl-py==0.9.0
asn1crypto==1.3.0
astor==0.8.0
attrs==19.3.0
backcall==0.1.0
beautifulsoup4==4.8.2
bleach==3.1.0
blis==0.2.4
Bottleneck==1.3.1
certifi==2019.11.28
cffi==1.14.0
chardet==3.0.4
click==7.1.1
cryptography==2.8
cycler==0.10.0
cymem==2.0.2
dataclasses==0.6
decorator==4.4.1
defusedxml==0.6.0
efficientnet==1.1.0
entrypoints==0.3
fastai==1.0.60
fastprogress==0.2.2
gast==0.3.3
glob3==0.0.1
google-pasta==0.1.8
grpcio==1.16.1
h5py==2.10.0
idna==2.8
imageio==2.8.0
importlib-metadata==1.5.0
imutils==0.5.3
ipykernel==5.1.4
ipython==7.12.0
ipython-genutils==0.2.0
jedi==0.16.0
Jinja2==2.11.1
joblib==0.14.1
jsonschema==3.2.0
jupyter-client==5.3.4
jupyter-core==4.6.1
Keras==2.2.4
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.0
kiwisolver==1.1.0
Markdown==3.1.1
MarkupSafe==1.1.1
matplotlib==3.1.3
mistune==0.8.4
mkl-fft==1.0.15
mkl-random==1.1.0
mkl-service==2.3.0
murmurhash==1.0.2
nbconvert==5.6.1
nbformat==5.0.4
networkx==2.4
notebook==6.0.3
numexpr==2.7.1
numpy==1.18.1
olefile==0.46
packaging==20.1
pandas==1.0.1
pandocfilters==1.4.2
parso==0.6.1
pexpect==4.8.0
pickleshare==0.7.5
Pillow==7.1.0
plac==0.9.6
preshed==2.0.1
prometheus-client==0.7.1
prompt-toolkit==3.0.3
protobuf==3.11.3
ptyprocess==0.6.0
pycparser==2.19
pygame==1.9.6
Pygments==2.5.2
pyOpenSSL==19.1.0
pyparsing==2.4.6
pyrsistent==0.15.7
PySocks==1.7.1
python-dateutil==2.8.1
pytz==2019.3
PyWavelets==1.1.1
PyYAML==5.3
pyzmq==18.1.1
requests==2.22.0
scikit-image==0.16.2
scikit-learn==0.22.1
scipy==1.4.1
Send2Trash==1.5.0
six==1.14.0
soupsieve==1.9.5
spacy==2.1.8
srsly==0.1.0
tensorboard==1.14.0
tensorflow==1.14.0
tensorflow-estimator==1.14.0
termcolor==1.1.0
terminado==0.8.3
testpath==0.4.4
thinc==7.0.8
torch==1.3.1
torchvision==0.4.2
tornado==6.0.3
tqdm==4.42.1
traitlets==4.3.3
urllib3==1.25.8
wasabi==0.2.2
wcwidth==0.1.8
webencodings==0.5.1
Werkzeug==1.0.0
wrapt==1.11.2
zipp==2.2.0
Loading

0 comments on commit a01c2bf

Please sign in to comment.