Spaces:
Runtime error
Runtime error
Commit
•
8c3c406
1
Parent(s):
77b5632
created export.pkl file
Browse files- .gitignore +4 -1
- model_training.ipynb +0 -0
- model_training.py +69 -0
.gitignore
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
-
|
|
|
|
|
|
|
2 |
|
3 |
# Byte-compiled / optimized / DLL files
|
4 |
__pycache__/
|
|
|
1 |
+
#*.pkl
|
2 |
+
data*/
|
3 |
+
|
4 |
+
|
5 |
|
6 |
# Byte-compiled / optimized / DLL files
|
7 |
__pycache__/
|
model_training.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
model_training.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastbook import *
|
2 |
+
from fastai.vision.widgets import *
|
3 |
+
|
4 |
+
## Gathering Data
|
5 |
+
|
6 |
+
path = Path('data_devices')
|
7 |
+
|
8 |
+
device_types = 'laptop','desktop pc','mobile phone'
|
9 |
+
|
10 |
+
if not path.exists():
|
11 |
+
path.mkdir()
|
12 |
+
for o in device_types:
|
13 |
+
dest = (path/o)
|
14 |
+
dest.mkdir(exist_ok=True)
|
15 |
+
results = search_images_ddg(f'{o}', max_images=100)
|
16 |
+
# results = search_images_bing(key, f'{o} bear')
|
17 |
+
# download_images(dest, urls=results.attrgot('contentUrl'))
|
18 |
+
download_images(dest, urls=results)
|
19 |
+
fns = get_image_files(path)
|
20 |
+
|
21 |
+
|
22 |
+
failed = verify_images(fns)
|
23 |
+
|
24 |
+
|
25 |
+
failed.map(Path.unlink);
|
26 |
+
|
27 |
+
#*
|
28 |
+
## From Data to DataLoaders
|
29 |
+
devices = DataBlock(
|
30 |
+
blocks=(ImageBlock, CategoryBlock),
|
31 |
+
get_items=get_image_files,
|
32 |
+
splitter=RandomSplitter(valid_pct=0.2, seed=42),
|
33 |
+
get_y=parent_label,
|
34 |
+
item_tfms=Resize(128))
|
35 |
+
dls = devices.dataloaders(path)
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
### Data Augmentation
|
42 |
+
|
43 |
+
|
44 |
+
## Training Your Model, and Using It to Clean Your Data
|
45 |
+
devices = devices.new(
|
46 |
+
item_tfms=RandomResizedCrop(224, min_scale=0.5),
|
47 |
+
batch_tfms=aug_transforms())
|
48 |
+
dls = devices.dataloaders(path)
|
49 |
+
learn = vision_learner(dls, resnet18, metrics=error_rate)
|
50 |
+
learn.fine_tune(4)
|
51 |
+
interp = ClassificationInterpretation.from_learner(learn)
|
52 |
+
interp.plot_confusion_matrix()
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
## Turning Your Model into an Online Application
|
58 |
+
|
59 |
+
### Using the Model for Inference
|
60 |
+
learn.export()
|
61 |
+
path = Path()
|
62 |
+
path.ls(file_exts='.pkl')
|
63 |
+
learn_inf = load_learner(path/'export.pkl')
|
64 |
+
query02 = "dell inspiron"
|
65 |
+
urls = search_images_ddg(query02, max_images = 5 )
|
66 |
+
dest = f'data_test/{query02}.jpg'
|
67 |
+
download_url(urls[0], dest)
|
68 |
+
learn_inf.predict(dest)
|
69 |
+
|