From 536687c05bb127d50249692c6354dcd6b5bc7c39 Mon Sep 17 00:00:00 2001 From: onb1259 Date: Mon, 6 Nov 2023 12:10:22 +0100 Subject: [PATCH] added README, code cleanup --- .gitignore | 1 + README.md | 11 +++++++++++ requirements.txt | 1 + resnet_classifier_gradio.py | 25 ------------------------- 4 files changed, 13 insertions(+), 25 deletions(-) create mode 100644 README.md diff --git a/.gitignore b/.gitignore index 839e52e..00167f7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__ venv images +test_examples.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..5260315 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Gradio app for image classification with resnet18 + +This project implements a small [gradio](https://www.gradio.app/) app that takes a link to a iiif manifest as input, donwloads the images of the manifest and and applies Pytorchs's [resnet18](https://pytorch.org/vision/main/models/generated/torchvision.models.resnet18.html) image classification model to it. + +To run the webapp type + +```shell +python resnet_classifier_gradio.py +``` + +in your terminal to host it on http://127.0.0.1:7860 . diff --git a/requirements.txt b/requirements.txt index 8928d50..decdaff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ Pillow==10.0.0 torch==2.0.1 torchvision==0.15.2 gradio==3.40.1 +# currently gradio==4.x.x can not be used because there are some deprecated methods I use in the code diff --git a/resnet_classifier_gradio.py b/resnet_classifier_gradio.py index 8a7fccf..59ed187 100644 --- a/resnet_classifier_gradio.py +++ b/resnet_classifier_gradio.py @@ -77,11 +77,6 @@ def apply_model(example_id): res = inference(img) return res -def download_annotation(annotation): - # TODO write iiif annotation to file - print(annotation) - return 'current_manifest.json' - with gr.Blocks() as demo: with gr.Row(): @@ -93,29 +88,9 @@ with gr.Blocks() as demo: with gr.Column(): res_labels = gr.Label(type="confidences",num_top_classes=5) - export_manifest = gr.Button(value='Export annotation to manifest') - download_file = gr.File() load_manifest.click(update_examples, inputs=link, outputs=examples) examples.click(load_example, inputs=examples, outputs=preview) examples.click(apply_model, inputs=examples, outputs=res_labels) - export_manifest.click(download_annotation, inputs=res_labels, outputs=download_file) demo.launch() - -# toronto collections https://iiif.library.utoronto.ca/presentation/v2/collections/utl:root -# 72 foto collection https://iiif.library.ucla.edu/collections/ark%3A%2F21198%2Fzz00011f8m - -# test with -# https://iiif.onb.ac.at/presentation/ANNO/apz18411229/manifest/ -# single images -# https://digitalcollections.universiteitleiden.nl/iiif_manifest/item%3A1276167/manifest -# https://iiif.library.utoronto.ca/presentation/v2/mdl:G3462_A16_P94_17_1910/manifest -# smaller books -# https://iiif.library.utoronto.ca/presentation/v2/anatomia:RBAI004/manifest -# https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00094542/manifest -# https://view.nls.uk/manifest/7549/75496599/manifest.json -# -# https://manifests.sub.uni-goettingen.de/iiif/presentation/PPN38180691X_Tafeln/manifest?version=6cb22eed - - -- GitLab