Mask Detector w/ FastAI and Streamlit Sharing

Jack Harding
Dec 11, 2020 · 3 min read

Introduction

Bing API

def search_images_bing(key, term, max_images: int = 150, **kwargs):
params = {‘q’:term, ‘count’:max_images}
headers = {“Ocp-Apim-Subscription-Key”:key}
search_url = “https://api.bing.microsoft.com/v7.0/images/search”
response = requests.get(search_url, headers=headers, params=params)
response.raise_for_status()
search_results = response.json()
return L(search_results[‘value’])
def make_category(cat, path, label):                         
if not path.exists():
path.mkdir()
dest = (path/label)
dest.mkdir(exist_ok=True)
results = search_images_bing(key, cat)
download_images(dest, urls=results.attrgot('contentUrl'))

Model Training

mask_detector
├── train
│ ├── mask
│ │ ├── img_1.jpeg
│ │ └── img_2.jpeg
│ └── no_mask
│ ├── img_3.jpeg
│ └── img_4.jpeg
└── valid
├── mask
│ ├── img_5.jpeg
│ └── img_6.jpeg
└── no_mask
├── img_7.jpeg
└── img_8.jpeg
masks = DataBlock(
blocks=(ImageBlock, CategoryBlock),
get_items=get_image_files(path),
splitter=RandomSplitter(valid_pct=0.2, seed=42),
get_y=parent_label,
item_tfms=Resize(128))

Streamlit Hosting

Streamlit Sharing App Deployment

Beard Skew

Photo by Frank Marino on Unsplash
make_category('peoples faces with covid mask', path, 'mask')make_category('clean shaven face', path, 'no_mask')make_category('bearded face', path, 'beard')

Resources

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data…

Sign up for Analytics Vidhya News Bytes

By Analytics Vidhya

Latest news from Analytics Vidhya on our Hackathons and some of our best articles! Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Jack Harding

Written by

Data Scientist | BSc Computer Engineering | jacklinc.github.io

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store