From 956205d0568577d403985872e26c2fe8049b81e9 Mon Sep 17 00:00:00 2001 From: kshitijrajsharma Date: Mon, 10 Apr 2023 20:03:33 +0545 Subject: [PATCH] added model and training info --- .../Layout/Start/Prediction/Prediction.js | 134 ++++++++++++++++-- 1 file changed, 119 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/Layout/Start/Prediction/Prediction.js b/frontend/src/components/Layout/Start/Prediction/Prediction.js index 31d70427..3a827c92 100644 --- a/frontend/src/components/Layout/Start/Prediction/Prediction.js +++ b/frontend/src/components/Layout/Start/Prediction/Prediction.js @@ -1,5 +1,13 @@ import LoadingButton from "@mui/lab/LoadingButton"; -import { Alert, Button, Grid } from "@mui/material"; +import { + Alert, + Button, + Grid, + Box, + CircularProgress, + Paper, + Typography, +} from "@mui/material"; import React, { useContext, useEffect, useRef, useState } from "react"; import { FeatureGroup, @@ -29,6 +37,61 @@ const Prediction = () => { window.innerHeight, ]); const [josmEnabled, setJosmEnabled] = useState(false); + const [modelInfo, setModelInfo] = useState(null); + const [loading, setLoading] = useState(false); + + const fetchData = async () => { + setLoading(true); + try { + // Fetch model information + const modelRes = await axios.get(`/model/${id}`); + const { + name, + published_training: trainingId, + dataset: datasetId, + } = modelRes.data; + + // Fetch training information + const trainingRes = await axios.get(`/training/${trainingId}`); + const { accuracy, description, zoom_level: zoomLevel } = trainingRes.data; + + // Fetch workspace data + const workspaceRes = await axios.get( + `/workspace/dataset_${datasetId}/output/training_${trainingId}/` + ); + const { dir } = workspaceRes.data; + + // Calculate model size + let modelSize = 0; + if (dir["checkpoint.h5"]) { + modelSize = dir["checkpoint.h5"].size; + } else if (dir["checkpoint.tf"]) { + modelSize = dir["checkpoint.tf"].size; + } + + // Convert bytes to human-readable format + const modelSizeInMB = ((modelSize / 1024) * 0.001).toFixed(2); + + // Set the state with the fetched data + setModelInfo({ + id, + name, + lastModified: modelRes.data.last_modified, + trainingId, + trainingDescription: description, + trainingZoomLevel: zoomLevel, + trainingAccuracy: accuracy, + modelSize: modelSizeInMB, + }); + } catch (error) { + console.error(error); + } finally { + setLoading(false); + } + }; + useEffect(() => { + fetchData(); + }, []); useEffect(() => { if (!apiCallInProgress) { @@ -97,6 +160,7 @@ const Prediction = () => { isLoading: predictionLoading, } = useMutation(async () => { setApiCallInProgress(true); + setResponseTime(0); const headers = { "access-token": accessToken, }; @@ -114,7 +178,7 @@ const Prediction = () => { const startTime = new Date().getTime(); // measure start time const res = await axios.post(`/prediction/`, body, { headers }); const endTime = new Date().getTime(); // measure end time - setResponseTime((endTime - startTime) / 1000); // calculate and store response time in seconds + setResponseTime(((endTime - startTime) / 1000).toFixed(0)); // calculate and store response time in seconds setApiCallInProgress(false); if (res.error) { setError( @@ -239,21 +303,61 @@ const Prediction = () => { callPredict(); }} > - Detect + Run Prediction {map && ( - <> -
-
- Zoom : {JSON.stringify(zoom)} -
- Model : {id} -
- Response : {responseTime} sec -
-
- + + + Current Zoom: {JSON.stringify(zoom)} + + Response: {responseTime} sec + + {loading ? ( + + + + ) : ( + modelInfo && ( + + + Loaded Model + + + Model ID: {modelInfo.id} + + + Model Name: {modelInfo.name} + + + Model Last Modified:{" "} + {new Date(modelInfo.lastModified).toLocaleString()} + + + Published Training + + + Training ID: {modelInfo.trainingId} + + + Training Description:{" "} + {modelInfo.trainingDescription} + + + Training Zoom Level:{" "} + {modelInfo.trainingZoomLevel} + + + Training Accuracy:{" "} + {modelInfo.trainingAccuracy} + + + Model Size: {modelInfo.modelSize} MB + + + ) + )} + )} {error && {error}} {predictions && ( @@ -262,7 +366,7 @@ const Prediction = () => { color="secondary" onClick={openWithJosm} > - Open with JOSM + Open Results with JOSM )}