Skip to content

Commit

Permalink
Merge pull request #99 from hotosm/feature/confidence
Browse files Browse the repository at this point in the history
Added confidence level option on predictions
  • Loading branch information
kshitijrajsharma authored Apr 11, 2023
2 parents 0e5c358 + d74184d commit 99fb8e3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
6 changes: 6 additions & 0 deletions backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,18 @@ class PredictionParamSerializer(serializers.Serializer):
bbox = serializers.ListField(child=serializers.FloatField(), required=True)
model_id = serializers.IntegerField(required=True)
zoom_level = serializers.IntegerField(required=True)
confidence = serializers.IntegerField(required=False)
source = serializers.URLField(required=False)

def validate(self, data):
"""
Check supplied data
"""
if "confidence" in data:
if data["confidence"] < 0 or data["confidence"] > 100:
raise serializers.ValidationError(
f"""Invalid Confidence threshold : {data["confidence"]}, Should be between 0-100"""
)
if len(data["bbox"]) != 4:
raise serializers.ValidationError("Not a valid bbox")
if data["zoom_level"] < 18 or data["zoom_level"] > 22:
Expand Down
3 changes: 3 additions & 0 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ def post(self, request, *args, **kwargs):
model_path,
temp_path,
prediction_output,
deserialized_data["confidence"] / 100
if "confidence" in deserialized_data
else 0.5,
)
future.result(
timeout=45
Expand Down
41 changes: 37 additions & 4 deletions frontend/src/components/Layout/Start/Prediction/Prediction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import {
Paper,
Typography,
} from "@mui/material";
import {
FormControl,
InputLabel,
Tooltip,
MenuItem,
Select,
} from "@mui/material";

import React, { useContext, useEffect, useRef, useState } from "react";
import {
FeatureGroup,
Expand All @@ -28,6 +36,7 @@ const Prediction = () => {
const [josmLoading, setJosmLoading] = useState(false);

const [apiCallInProgress, setApiCallInProgress] = useState(false);
const [confidence, setConfidence] = useState(50);

const [map, setMap] = useState(null);
const [zoom, setZoom] = useState(0);
Expand Down Expand Up @@ -177,6 +186,7 @@ const Prediction = () => {
model_id: id,
zoom_level: zoom,
source: dataset.source_imagery,
confidence: confidence,
};
const startTime = new Date().getTime(); // measure start time
const res = await axios.post(`/prediction/`, body, { headers });
Expand Down Expand Up @@ -311,13 +321,36 @@ const Prediction = () => {
>
Run Prediction
</LoadingButton>
<Box display="flex" alignItems="center" mt={1}>
<Tooltip title="Select confidence threshold probability for filtering out low-confidence predictions">
<Typography variant="h7" style={{ marginRight: "8px" }}>
<strong>Confidence: </strong>
</Typography>
</Tooltip>
<FormControl size="small">
<Select
value={confidence}
onChange={(e) => setConfidence(e.target.value)}
style={{ width: "90px" }}
disableUnderline
MenuProps={{ disablePortal: true }}
>
<MenuItem value={25}>25 %</MenuItem>
<MenuItem value={50}>50 %</MenuItem>
<MenuItem value={75}>75 %</MenuItem>
<MenuItem value={90}>90 %</MenuItem>
</Select>
</FormControl>
</Box>

{map && (
<Box mt={3}>
<Typography variant="h6">
Current Zoom: {JSON.stringify(zoom)}
<Box>
<Typography variant="h7">
<strong> Current Zoom:</strong> {JSON.stringify(zoom)}
</Typography>
<Typography variant="h7">
<strong> Response: </strong> {responseTime} sec
</Typography>
<Typography variant="h7">Response: {responseTime} sec</Typography>

{loading ? (
<Box display="flex" justifyContent="center" mt={2}>
Expand Down

0 comments on commit 99fb8e3

Please sign in to comment.