Save init model in session state
Browse filesSave the init model in the session state to prevent model init again when try with another images
app.py
CHANGED
|
@@ -23,7 +23,6 @@ map_sampleid_name = {
|
|
| 23 |
'tee': 'e2d8637a-5478-429d-a2a8-3d5859dbc64d.jpeg',
|
| 24 |
'bracelet': 'e78518ac-0f54-4483-a233-fad6511f0b86.jpeg'
|
| 25 |
}
|
| 26 |
-
init_model_required = True
|
| 27 |
|
| 28 |
def init_model(init_model_required):
|
| 29 |
|
|
@@ -79,14 +78,26 @@ if btn_click:
|
|
| 79 |
|
| 80 |
if image is not None:
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
with st.spinner('Generating Caption...'):
|
| 86 |
|
| 87 |
image_col, caption_text = st.columns(2)
|
| 88 |
image_col.header("Image")
|
| 89 |
-
image_col.image(image, use_column_width = True)
|
| 90 |
|
| 91 |
#Preprocess the image
|
| 92 |
#Inferance on GPU. When used this on GPU will get errors like: "slow_conv2d_cpu" not implemented for 'Half'" , " Input type (float) and bias type (struct c10::Half)"
|
|
|
|
| 23 |
'tee': 'e2d8637a-5478-429d-a2a8-3d5859dbc64d.jpeg',
|
| 24 |
'bracelet': 'e78518ac-0f54-4483-a233-fad6511f0b86.jpeg'
|
| 25 |
}
|
|
|
|
| 26 |
|
| 27 |
def init_model(init_model_required):
|
| 28 |
|
|
|
|
| 78 |
|
| 79 |
if image is not None:
|
| 80 |
|
| 81 |
+
if 'init_model_required' not in st.session_state:
|
| 82 |
+
with st.spinner('Initializing model...'):
|
| 83 |
+
|
| 84 |
+
init_model_required = True
|
| 85 |
+
processor, model, init_model_required = init_model(init_model_required)
|
| 86 |
+
|
| 87 |
+
#Save session init model in session state
|
| 88 |
+
if 'init_model_required' not in st.session_state:
|
| 89 |
+
st.session_state.init_model_required = init_model_required
|
| 90 |
+
st.session_state.processor = processor
|
| 91 |
+
st.session_state.model = model
|
| 92 |
+
else:
|
| 93 |
+
processor = st.session_state.processor
|
| 94 |
+
model = st.session_state.model
|
| 95 |
|
| 96 |
with st.spinner('Generating Caption...'):
|
| 97 |
|
| 98 |
image_col, caption_text = st.columns(2)
|
| 99 |
image_col.header("Image")
|
| 100 |
+
image_col.image(image.resize((252,252)), use_column_width = True)
|
| 101 |
|
| 102 |
#Preprocess the image
|
| 103 |
#Inferance on GPU. When used this on GPU will get errors like: "slow_conv2d_cpu" not implemented for 'Half'" , " Input type (float) and bias type (struct c10::Half)"
|