rmm commited on
Commit
c3cf604
·
1 Parent(s): e90cc61

chore: removing duplicate file (right one is in classifier subdir)

Browse files
Files changed (1) hide show
  1. src/classifier_image.py +0 -70
src/classifier_image.py DELETED
@@ -1,70 +0,0 @@
1
- import streamlit as st
2
- import logging
3
- import os
4
-
5
- # get a global var for logger accessor in this module
6
- LOG_LEVEL = logging.DEBUG
7
- g_logger = logging.getLogger(__name__)
8
- g_logger.setLevel(LOG_LEVEL)
9
-
10
- from grid_maker import gridder
11
- import hf_push_observations as sw_push_obs
12
- import utils.metadata_handler as meta_handler
13
- import whale_viewer as sw_wv
14
-
15
- def cetacean_classify(cetacean_classifier, tab_inference):
16
- files = st.session_state.files
17
- images = st.session_state.images
18
- observations = st.session_state.observations
19
-
20
- batch_size, row_size, page = gridder(files)
21
-
22
- grid = st.columns(row_size)
23
- col = 0
24
-
25
- for file in files:
26
- image = images[file.name]
27
-
28
- with grid[col]:
29
- st.image(image, use_column_width=True)
30
- observation = observations[file.name].to_dict()
31
- # run classifier model on `image`, and persistently store the output
32
- out = cetacean_classifier(image) # get top 3 matches
33
- st.session_state.whale_prediction1 = out['predictions'][0]
34
- st.session_state.classify_whale_done = True
35
- msg = f"[D]2 classify_whale_done: {st.session_state.classify_whale_done}, whale_prediction1: {st.session_state.whale_prediction1}"
36
- g_logger.info(msg)
37
-
38
- # dropdown for selecting/overriding the species prediction
39
- if not st.session_state.classify_whale_done:
40
- selected_class = st.sidebar.selectbox("Species", sw_wv.WHALE_CLASSES,
41
- index=None, placeholder="Species not yet identified...",
42
- disabled=True)
43
- else:
44
- pred1 = st.session_state.whale_prediction1
45
- # get index of pred1 from WHALE_CLASSES, none if not present
46
- print(f"[D] pred1: {pred1}")
47
- ix = sw_wv.WHALE_CLASSES.index(pred1) if pred1 in sw_wv.WHALE_CLASSES else None
48
- selected_class = tab_inference.selectbox("Species", sw_wv.WHALE_CLASSES, index=ix)
49
-
50
- observation['predicted_class'] = selected_class
51
- if selected_class != st.session_state.whale_prediction1:
52
- observation['class_overriden'] = selected_class
53
-
54
- st.session_state.public_observation = observation
55
- st.button(f"Upload observation for {file.name} to THE INTERNET!", on_click=sw_push_obs.push_observations)
56
- # TODO: the metadata only fills properly if `validate` was clicked.
57
- st.markdown(meta_handler.metadata2md())
58
-
59
- msg = f"[D] full observation after inference: {observation}"
60
- g_logger.debug(msg)
61
- print(msg)
62
- # TODO: add a link to more info on the model, next to the button.
63
-
64
- whale_classes = out['predictions'][:]
65
- # render images for the top 3 (that is what the model api returns)
66
- #with tab_inference:
67
- st.title(f"Species detected for {file.name}")
68
- for i in range(len(whale_classes)):
69
- sw_wv.display_whale(whale_classes, i)
70
- col = (col + 1) % row_size