-
Notifications
You must be signed in to change notification settings - Fork 2
/
gender_identifier.py
50 lines (39 loc) · 1.13 KB
/
gender_identifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""gender_Identifier.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1PwDijz67Ds_h6JiQm_TIAByiyFM65qU7
"""
from fastbook import *
from fastai import *
from fastai.vision.widgets import *
people_type = 'female','male'
path = Path('people')
if not path.exists():
path.mkdir()
for o in people_type:
dest = (path/o)
dest.mkdir(exist_ok=True)
results = search_images_ddg(f'face of {o}',max_images=50)
download_images(dest,urls=results,max_pics=50)
fns = get_image_files(path)
failed = verify_images(fns)
failed.map(Path.unlink)
people = DataBlock(
blocks=(ImageBlock, CategoryBlock),
get_items=get_image_files,
splitter = RandomSplitter(valid_pct=0.2,seed=42),
get_y=parent_label,
item_tfms=Resize(128)
)
people = people.new(
item_tfms=RandomResizedCrop(224,min_scale=0.5),
batch_tfms=aug_transforms()
)
dls = people.dataloaders(path)
learn = vision_learner(dls,resnet50, metrics=accuracy)
learn.fine_tune(5)
learn.export()
path = Path()
path.ls(file_exts='.pkl')
learn_inf = load_learner(path/'export.pkl')