-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
53 lines (34 loc) · 1.35 KB
/
app.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
51
52
53
from glob import glob
#from fastai.vision import *
from fastai.vision.all import *
import sys
#data = ImageDataLoaders.from_folder("data/input/porn",
# train='train',
# valid='test',
# num_workers=12,
# ds_tfms=get_transforms(),
# size=224).normalize(imagenet_stats)
#
if not "--path" in sys.argv:
print("set path")
exit()
path = sys.argv[sys.argv.index("--path") + 1] if "--path" in sys.argv else ""
#print(get_image_files("input"))
#learn = vision_learner(dls, resnet34, metrics=error_rate).to_fp16()
#learn.fine_tune(1)
label_function = lambda f: str(f).split("/")[-2]
items = DataBlock(blocks=(ImageBlock, CategoryBlock),
get_items=get_image_files,
splitter=RandomSplitter(),
get_y=label_function,
item_tfms=Resize(224, method=ResizeMethod.Pad))
loader = items.dataloaders(path)
#Проверка закачки
if "--show-batch" in sys.argv:
loader.show_batch(max_n=9)
print("loader.show_batch()")
if "--learn" in sys.argv:
print("Go learn!")
learn = vision_learner(loader, resnet34, metrics=error_rate)
learn.fine_tune(10)
lear.save("model")