Skip to content

Commit

Permalink
Add FPS measurement and display
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoelTT committed Jan 19, 2025
1 parent 94e0182 commit 363699a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const ObjectDetectionComponent: React.FC = () => {
<div className="text-sm text-gray-500">
Input image width and height: {metadata.width} x {metadata.height}
<br />
Time to inference: {metadata.inferenceTime} sec
Frame Rate: {metadata.inferenceTime} FPS
</div>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ export const runInference = async (
}

try {
const startTime = performance.now();
const response = await axios.post(
`/models-api/object-detection/`,
formData,
{
headers: { "Content-Type": "multipart/form-data" },
},
);
const endTime = performance.now();
const requestLatency = endTime - startTime;
// handle imageSourceElement types
let width, height;
if (imageSourceElement instanceof HTMLCanvasElement) {
Expand All @@ -42,7 +45,7 @@ export const runInference = async (
const detectionMetadata: DetectionMetadata = {
width: width,
height: height,
inferenceTime: response.data.inference_time || 33.333,
inferenceTime: response.data.inference_time || (1/(requestLatency/1000)).toFixed(2),
};
const detections: Detection[] = response.data.map(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit 363699a

Please sign in to comment.