cleanup
Browse files
app.py
CHANGED
|
@@ -50,12 +50,12 @@ def apply_classifier(img, context={}, detect=False):
|
|
| 50 |
result = {}
|
| 51 |
if detect:
|
| 52 |
if not context.get("clf", None):
|
| 53 |
-
context["clf"] = pipeline(
|
|
|
|
| 54 |
result = context["clf"](Image.fromarray((img*255).astype(np.uint8)))
|
| 55 |
else:
|
| 56 |
result = [{"score": 0., "label": "No classification"}]*5
|
| 57 |
context["result"] = result
|
| 58 |
-
# return result
|
| 59 |
|
| 60 |
|
| 61 |
def display_result(context={}):
|
|
@@ -64,10 +64,14 @@ def display_result(context={}):
|
|
| 64 |
SingleCurve(
|
| 65 |
x=[id, id, id+1, id+1],
|
| 66 |
y=[0, r['score'], r['score'], 0],
|
| 67 |
-
label=r["label"],
|
| 68 |
)
|
| 69 |
for id, r in enumerate(result_dict)]
|
| 70 |
-
result_curves = Curve(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
return result_curves
|
| 72 |
|
| 73 |
# -------------------
|
|
@@ -87,7 +91,7 @@ if __name__ == "__main__":
|
|
| 87 |
parser = argparse.ArgumentParser()
|
| 88 |
parser.add_argument("-b", "--backend", type=str,
|
| 89 |
choices=BACKEND_OPTIONS, default=BACKEND_OPTIONS[0])
|
| 90 |
-
args = parser.parse_args()
|
| 91 |
md_description = "# 🔍 EXAMPLE Interactive-pipe + machine learning \n"
|
| 92 |
md_description += "```python\n"+open(__file__, 'r').read()+"```\n"
|
| 93 |
interactive_pipeline(gui=args.backend, markdown_description=md_description)(
|
|
|
|
| 50 |
result = {}
|
| 51 |
if detect:
|
| 52 |
if not context.get("clf", None):
|
| 53 |
+
context["clf"] = pipeline(
|
| 54 |
+
"image-classification", model="google/vit-base-patch16-224")
|
| 55 |
result = context["clf"](Image.fromarray((img*255).astype(np.uint8)))
|
| 56 |
else:
|
| 57 |
result = [{"score": 0., "label": "No classification"}]*5
|
| 58 |
context["result"] = result
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
def display_result(context={}):
|
|
|
|
| 64 |
SingleCurve(
|
| 65 |
x=[id, id, id+1, id+1],
|
| 66 |
y=[0, r['score'], r['score'], 0],
|
| 67 |
+
label=r["label"], linestyle="-",
|
| 68 |
)
|
| 69 |
for id, r in enumerate(result_dict)]
|
| 70 |
+
result_curves = Curve(
|
| 71 |
+
curves,
|
| 72 |
+
ylim=[0, 1],
|
| 73 |
+
title=f"{result_dict[0]['label']} ({result_dict[0]['score']:.2%})"
|
| 74 |
+
)
|
| 75 |
return result_curves
|
| 76 |
|
| 77 |
# -------------------
|
|
|
|
| 91 |
parser = argparse.ArgumentParser()
|
| 92 |
parser.add_argument("-b", "--backend", type=str,
|
| 93 |
choices=BACKEND_OPTIONS, default=BACKEND_OPTIONS[0])
|
| 94 |
+
args = parser.parse_args()
|
| 95 |
md_description = "# 🔍 EXAMPLE Interactive-pipe + machine learning \n"
|
| 96 |
md_description += "```python\n"+open(__file__, 'r').read()+"```\n"
|
| 97 |
interactive_pipeline(gui=args.backend, markdown_description=md_description)(
|