From 2e4ec6c4fc166caf43444495b96348cafffdf431 Mon Sep 17 00:00:00 2001 From: Runbo Jiang Date: Wed, 31 Jan 2024 15:57:26 -0800 Subject: [PATCH 1/4] Correct the selected_indices --- src/app_layout.py | 1 - src/frontend.py | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app_layout.py b/src/app_layout.py index 5f1ddbf..2d98025 100644 --- a/src/app_layout.py +++ b/src/app_layout.py @@ -1,6 +1,5 @@ from dash import Dash, html, dcc import dash_bootstrap_components as dbc -from dash import dcc from dash_iconify import DashIconify from dash.long_callback import DiskcacheLongCallbackManager import plotly.graph_objects as go diff --git a/src/frontend.py b/src/frontend.py index 2646781..9ae3f29 100755 --- a/src/frontend.py +++ b/src/frontend.py @@ -405,8 +405,14 @@ def update_scatter_plot(latent_vectors, selected_cluster, selected_label, scatte n_components = children['props']['children'][0]["props"]["children"][1]["props"]["value"] + # if selected_data is not None and len(selected_data.get('points', [])) > 0: + # selected_indices = [point['customdata'][0] for point in selected_data['points']] if selected_data is not None and len(selected_data.get('points', [])) > 0: - selected_indices = [point['customdata'][0] for point in selected_data['points']] + selected_indices = [] + for point in selected_data['points']: + if 'customdata' in point and len(point['customdata']): + selected_indices.append(point['customdata'][0]) + print("selected indices: ", selected_indices) else: selected_indices = None @@ -614,5 +620,3 @@ def update_trained_model_list(interval): if __name__ == '__main__': app.run_server(debug=True, host='0.0.0.0', port=8070, ) - - From 02d821673d3d1eda1dd4edef8d9aa7aa465bb36a Mon Sep 17 00:00:00 2001 From: Runbo Jiang Date: Fri, 2 Feb 2024 17:45:23 -0800 Subject: [PATCH 2/4] Comment out data-clinic-intercal and fix lasso select problem --- src/app_layout.py | 12 +++++------ src/frontend.py | 55 ++++++++++++++++++++++++++--------------------- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/app_layout.py b/src/app_layout.py index 2d98025..dab33be 100644 --- a/src/app_layout.py +++ b/src/app_layout.py @@ -210,12 +210,12 @@ max_intervals=-1, # keep triggering indefinitely, None n_intervals=0, ), - dcc.Interval( - id='interval-for-dc', - interval=1000, # in milliseconds - max_intervals=-1, # keep triggering indefinitely, None - n_intervals=0, - ), + # dcc.Interval( + # id='interval-for-dc', + # interval=1000, # in milliseconds + # max_intervals=-1, # keep triggering indefinitely, None + # n_intervals=0, + # ), ] ) diff --git a/src/frontend.py b/src/frontend.py index 9ae3f29..7cc5694 100755 --- a/src/frontend.py +++ b/src/frontend.py @@ -515,10 +515,11 @@ def update_heatmap(click_data, selected_data, display_option, input_data): [ State('clusters', 'data'), State('input_labels', 'data'), - State('label_schema', 'data') + State('label_schema', 'data'), + State('latent_vectors', 'data'), ] ) -def update_statistics(selected_data, clusters, assigned_labels, label_names): +def update_statistics(selected_data, clusters, assigned_labels, label_names, latent_vectors): ''' This callback update the statistics panel Args: @@ -529,12 +530,16 @@ def update_statistics(selected_data, clusters, assigned_labels, label_names): Returns: [num_images, clusters, labels]: statistics ''' + clusters = np.array(clusters) assigned_labels = np.array(assigned_labels) + if selected_data is not None and len(selected_data['points']) > 0: selected_indices = [point['customdata'][0] for point in selected_data['points']] # Access customdata for the original indices - selected_clusters = clusters[selected_indices] + selected_clusters = [] + if clusters: + selected_clusters = clusters[selected_indices] selected_labels = assigned_labels[selected_indices] num_images = len(selected_indices) @@ -594,28 +599,28 @@ def toggle_modal(n_submit, n_apply, return False, "No alert." -@app.callback( - Output('feature-vector-model-list', 'options'), - Input('interval-for-dc', 'n_intervals'), - # prevent_initial_call=True -) -def update_trained_model_list(interval): - ''' - This callback updates the list of trained models - Args: - tab_value: Tab option - prob_refresh_n_clicks: Button to refresh the list of probability-based trained models - similarity_refresh_n_clicks: Button to refresh the list of similarity-based trained models - Returns: - prob_model_list: List of trained models in mlcoach - similarity_model_list: List of trained models in data clinic and mlcoach - ''' - data_clinic_models = get_trained_models_list(USER, 'data_clinic') - ml_coach_models = get_trained_models_list(USER, 'mlcoach') - feature_vector_models = data_clinic_models + ml_coach_models - print(feature_vector_models) - - return feature_vector_models +# @app.callback( +# Output('feature-vector-model-list', 'options'), +# Input('interval-for-dc', 'n_intervals'), +# # prevent_initial_call=True +# ) +# def update_trained_model_list(interval): +# ''' +# This callback updates the list of trained models +# Args: +# tab_value: Tab option +# prob_refresh_n_clicks: Button to refresh the list of probability-based trained models +# similarity_refresh_n_clicks: Button to refresh the list of similarity-based trained models +# Returns: +# prob_model_list: List of trained models in mlcoach +# similarity_model_list: List of trained models in data clinic and mlcoach +# ''' +# data_clinic_models = get_trained_models_list(USER, 'data_clinic') +# ml_coach_models = get_trained_models_list(USER, 'mlcoach') +# feature_vector_models = data_clinic_models + ml_coach_models +# #print(feature_vector_models) + +# return feature_vector_models if __name__ == '__main__': From a8486febc88bcf527b6a40c1e63231b90d678dd3 Mon Sep 17 00:00:00 2001 From: Runbo Jiang Date: Fri, 2 Feb 2024 17:53:58 -0800 Subject: [PATCH 3/4] Remove unnecessary state in update_statistics --- src/frontend.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/frontend.py b/src/frontend.py index 7cc5694..20ee027 100755 --- a/src/frontend.py +++ b/src/frontend.py @@ -516,10 +516,9 @@ def update_heatmap(click_data, selected_data, display_option, input_data): State('clusters', 'data'), State('input_labels', 'data'), State('label_schema', 'data'), - State('latent_vectors', 'data'), ] ) -def update_statistics(selected_data, clusters, assigned_labels, label_names, latent_vectors): +def update_statistics(selected_data, clusters, assigned_labels, label_names): ''' This callback update the statistics panel Args: From a25468fea856d969c224f4540ecbd71013bcff21 Mon Sep 17 00:00:00 2001 From: Runbo Jiang Date: Fri, 2 Feb 2024 19:00:52 -0800 Subject: [PATCH 4/4] Remove inerval related with data-clinic --- src/app_layout.py | 10 ++-------- src/frontend.py | 43 +++++++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/app_layout.py b/src/app_layout.py index dab33be..5664c1b 100644 --- a/src/app_layout.py +++ b/src/app_layout.py @@ -22,6 +22,8 @@ DOCKER_DATA = pathlib.Path.home() / 'data' #/app/work/data UPLOAD_FOLDER_ROOT = DOCKER_DATA / 'upload' #/app/work/data/upload +# DATA_CLINIC_OPTION = + #### SETUP DASH APP #### cache = diskcache.Cache("./cache") long_callback_manager = DiskcacheLongCallbackManager(cache) @@ -53,8 +55,6 @@ dbc.Label('Or select Data Clinic modal', className='mr-2'), dcc.Dropdown( id='feature-vector-model-list', - #options=DATA_OPTION, - #value = DATA_OPTION[0]['value'], clearable=False, style={'margin-bottom': '1rem'} ), @@ -210,12 +210,6 @@ max_intervals=-1, # keep triggering indefinitely, None n_intervals=0, ), - # dcc.Interval( - # id='interval-for-dc', - # interval=1000, # in milliseconds - # max_intervals=-1, # keep triggering indefinitely, None - # n_intervals=0, - # ), ] ) diff --git a/src/frontend.py b/src/frontend.py index 20ee027..5018236 100755 --- a/src/frontend.py +++ b/src/frontend.py @@ -598,28 +598,27 @@ def toggle_modal(n_submit, n_apply, return False, "No alert." -# @app.callback( -# Output('feature-vector-model-list', 'options'), -# Input('interval-for-dc', 'n_intervals'), -# # prevent_initial_call=True -# ) -# def update_trained_model_list(interval): -# ''' -# This callback updates the list of trained models -# Args: -# tab_value: Tab option -# prob_refresh_n_clicks: Button to refresh the list of probability-based trained models -# similarity_refresh_n_clicks: Button to refresh the list of similarity-based trained models -# Returns: -# prob_model_list: List of trained models in mlcoach -# similarity_model_list: List of trained models in data clinic and mlcoach -# ''' -# data_clinic_models = get_trained_models_list(USER, 'data_clinic') -# ml_coach_models = get_trained_models_list(USER, 'mlcoach') -# feature_vector_models = data_clinic_models + ml_coach_models -# #print(feature_vector_models) - -# return feature_vector_models +@app.callback( + Output('feature-vector-model-list', 'options'), + Input('interval-component', 'n_intervals'), +) +def update_trained_model_list(interval): + ''' + This callback updates the list of trained models + Args: + tab_value: Tab option + prob_refresh_n_clicks: Button to refresh the list of probability-based trained models + similarity_refresh_n_clicks: Button to refresh the list of similarity-based trained models + Returns: + prob_model_list: List of trained models in mlcoach + similarity_model_list: List of trained models in data clinic and mlcoach + ''' + data_clinic_models = get_trained_models_list(USER, 'data_clinic') + ml_coach_models = get_trained_models_list(USER, 'mlcoach') + feature_vector_models = data_clinic_models + ml_coach_models + #print(feature_vector_models) + + return feature_vector_models if __name__ == '__main__':