def display_uploaded_img(contents, fname, date): if contents is not None: original_img, resized_img = parse_image(contents, fname, date) img = np.expand_dims(resized_img, axis=0) prediction_array = model.predict(img) prediction = np.argmax(prediction_array) children = [ "Your uploaded image: ", html.Img(className="image", src=original_img), "Image fed the model: ", html.Img(className="image", src=create_img(resized_img)), f"The model thinks this is a {label_mapping[prediction]}", html.Button(id="clear-button", children="Remove Uploaded Image", n_clicks=0), ] return children
def display_selected_point(clickData): if not clickData: raise dash.exceptions.PreventUpdate idx = clickData["points"][0]["customdata"] img = np.expand_dims(all_images[idx], axis=0) prediction_array = model.predict(img) prediction = np.argmax(prediction_array) probability = np.round(prediction_array[0, prediction] * 100, 2) ground_truth = all_labels[idx] correct = prediction == ground_truth if correct: color = "green" else: color = "red" return [ create_img(all_images[idx]), [ f"prediction: {label_mapping[prediction]} ({probability}% certainty)", html.Br(), f"actual: {label_mapping[ground_truth]}", ], ]
def display_selected_point(hoverData): if not hoverData: return create_img(train_images[0]) idx = hoverData["points"][0]["customdata"] return create_img(all_images[idx])
html.Div( id="prediction", children=[ "Click on a point to display the Network's prediction", html.Br(), html.Br(), ], ), ], style={"height": "20%"}, ), html.Br(), html.Img( id="selected-data-graph", className="image", src=create_img( np.zeros((28, 28))), ), ], ) ], ), ], ), ], ), ], ), ]) @app.callback(