kamangir
commited on
Commit
•
5877e39
1
Parent(s):
845b45b
validating fashion_mnist train - kamangir/bolt#689
Browse files- image_classifier/__init__.py +1 -1
- image_classifier/__main__.py +2 -2
- image_classifier/classes.py +25 -18
image_classifier/__init__.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
name = "image_classifier"
|
2 |
|
3 |
-
version = "1.1.
|
4 |
|
5 |
description = "fashion-mnist + hugging-face + awesome-bash-cli"
|
|
|
1 |
name = "image_classifier"
|
2 |
|
3 |
+
version = "1.1.59"
|
4 |
|
5 |
description = "fashion-mnist + hugging-face + awesome-bash-cli"
|
image_classifier/__main__.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import argparse
|
2 |
from . import *
|
3 |
-
from .classes import
|
4 |
from .funcs import *
|
5 |
from abcli import file
|
6 |
import abcli.logging
|
@@ -112,7 +112,7 @@ parser.add_argument(
|
|
112 |
parser.add_argument(
|
113 |
"--window_size",
|
114 |
type=int,
|
115 |
-
default=
|
116 |
)
|
117 |
args = parser.parse_args()
|
118 |
|
|
|
1 |
import argparse
|
2 |
from . import *
|
3 |
+
from .classes import *
|
4 |
from .funcs import *
|
5 |
from abcli import file
|
6 |
import abcli.logging
|
|
|
112 |
parser.add_argument(
|
113 |
"--window_size",
|
114 |
type=int,
|
115 |
+
default=default_window_size,
|
116 |
)
|
117 |
args = parser.parse_args()
|
118 |
|
image_classifier/classes.py
CHANGED
@@ -12,15 +12,20 @@ import logging
|
|
12 |
|
13 |
logger = logging.getLogger(__name__)
|
14 |
|
|
|
|
|
15 |
|
16 |
class Image_Classifier(object):
|
17 |
def __init__(self):
|
18 |
self.class_names = []
|
19 |
self.model = None
|
20 |
-
self.params = {"convnet": False}
|
21 |
|
22 |
-
self.
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
|
25 |
def load(self, model_path):
|
26 |
success, self.class_names = file.load_json(f"{model_path}/class_names.json")
|
@@ -31,7 +36,9 @@ class Image_Classifier(object):
|
|
31 |
if not success:
|
32 |
return False
|
33 |
|
34 |
-
self.
|
|
|
|
|
35 |
|
36 |
try:
|
37 |
self.model = tf.keras.models.load_model(
|
@@ -43,15 +50,11 @@ class Image_Classifier(object):
|
|
43 |
crash_report("image_classifier.load({}) failed".format(model_path))
|
44 |
return False
|
45 |
|
46 |
-
self.window_size = int(
|
47 |
-
cache.read("{}.window_size".format(path.name(model_path)))
|
48 |
-
)
|
49 |
-
|
50 |
logger.info(
|
51 |
"{}.load({}x{}:{}): {}{} class(es): {}".format(
|
52 |
self.__class__.__name__,
|
53 |
-
self.window_size,
|
54 |
-
self.window_size,
|
55 |
path.name(model_path),
|
56 |
"convnet - " if self.params["convnet"] else "",
|
57 |
len(self.class_names),
|
@@ -60,8 +63,6 @@ class Image_Classifier(object):
|
|
60 |
)
|
61 |
self.model.summary()
|
62 |
|
63 |
-
self.object_name = path.name(model_path)
|
64 |
-
|
65 |
return True
|
66 |
|
67 |
def predict(self, test_images, test_labels, output_path="", page_count=-1):
|
@@ -169,7 +170,10 @@ class Image_Classifier(object):
|
|
169 |
try:
|
170 |
prediction = self.model.predict(
|
171 |
np.expand_dims(
|
172 |
-
cv2.resize(
|
|
|
|
|
|
|
173 |
axis=0,
|
174 |
)
|
175 |
)
|
@@ -247,9 +251,11 @@ class Image_Classifier(object):
|
|
247 |
crash_report("image_classifier.save({}) failed".format(model_path))
|
248 |
return False
|
249 |
|
250 |
-
self.object_name = path.name(model_path)
|
251 |
|
252 |
-
self.model_size = file.size(
|
|
|
|
|
253 |
|
254 |
if not file.save_json(
|
255 |
"{}/class_names.json".format(model_path), self.class_names
|
@@ -266,8 +272,10 @@ class Image_Classifier(object):
|
|
266 |
" | ".join(
|
267 |
[
|
268 |
"image_classifier",
|
269 |
-
self.object_name,
|
270 |
-
string.pretty_bytes(self.model_size)
|
|
|
|
|
271 |
string.pretty_shape(self.input_shape),
|
272 |
"/".join(string.shorten(self.class_names)),
|
273 |
"took {} / frame".format(
|
@@ -405,7 +413,6 @@ class Image_Classifier(object):
|
|
405 |
test_images,
|
406 |
np.argmax(test_labels, axis=1),
|
407 |
model_path,
|
408 |
-
cache=True,
|
409 |
page_count=10,
|
410 |
)
|
411 |
|
|
|
12 |
|
13 |
logger = logging.getLogger(__name__)
|
14 |
|
15 |
+
default_window_size = 28
|
16 |
+
|
17 |
|
18 |
class Image_Classifier(object):
|
19 |
def __init__(self):
|
20 |
self.class_names = []
|
21 |
self.model = None
|
|
|
22 |
|
23 |
+
self.params = {
|
24 |
+
"convnet": False,
|
25 |
+
"object_name": "",
|
26 |
+
"model_size": "",
|
27 |
+
"window_size": default_window_size,
|
28 |
+
}
|
29 |
|
30 |
def load(self, model_path):
|
31 |
success, self.class_names = file.load_json(f"{model_path}/class_names.json")
|
|
|
36 |
if not success:
|
37 |
return False
|
38 |
|
39 |
+
self.params["object_name"] = path.name(model_path)
|
40 |
+
|
41 |
+
self.params["model_size"] = file.size(f"{model_path}/image_classifier/model")
|
42 |
|
43 |
try:
|
44 |
self.model = tf.keras.models.load_model(
|
|
|
50 |
crash_report("image_classifier.load({}) failed".format(model_path))
|
51 |
return False
|
52 |
|
|
|
|
|
|
|
|
|
53 |
logger.info(
|
54 |
"{}.load({}x{}:{}): {}{} class(es): {}".format(
|
55 |
self.__class__.__name__,
|
56 |
+
self.params["window_size"],
|
57 |
+
self.params["window_size"],
|
58 |
path.name(model_path),
|
59 |
"convnet - " if self.params["convnet"] else "",
|
60 |
len(self.class_names),
|
|
|
63 |
)
|
64 |
self.model.summary()
|
65 |
|
|
|
|
|
66 |
return True
|
67 |
|
68 |
def predict(self, test_images, test_labels, output_path="", page_count=-1):
|
|
|
170 |
try:
|
171 |
prediction = self.model.predict(
|
172 |
np.expand_dims(
|
173 |
+
cv2.resize(
|
174 |
+
frame, (self.params["window_size"], self.params["window_size"])
|
175 |
+
)
|
176 |
+
/ 255.0,
|
177 |
axis=0,
|
178 |
)
|
179 |
)
|
|
|
251 |
crash_report("image_classifier.save({}) failed".format(model_path))
|
252 |
return False
|
253 |
|
254 |
+
self.params["object_name"] = path.name(model_path)
|
255 |
|
256 |
+
self.params["model_size"] = file.size(
|
257 |
+
"{}/image_classifier/model".format(model_path)
|
258 |
+
)
|
259 |
|
260 |
if not file.save_json(
|
261 |
"{}/class_names.json".format(model_path), self.class_names
|
|
|
272 |
" | ".join(
|
273 |
[
|
274 |
"image_classifier",
|
275 |
+
self.params["object_name"],
|
276 |
+
string.pretty_bytes(self.params["model_size"])
|
277 |
+
if self.params["model_size"]
|
278 |
+
else "",
|
279 |
string.pretty_shape(self.input_shape),
|
280 |
"/".join(string.shorten(self.class_names)),
|
281 |
"took {} / frame".format(
|
|
|
413 |
test_images,
|
414 |
np.argmax(test_labels, axis=1),
|
415 |
model_path,
|
|
|
416 |
page_count=10,
|
417 |
)
|
418 |
|