Skip to content

Commit

Permalink
Merge pull request #1153 from AI4Bharat/ocr-new
Browse files Browse the repository at this point in the history
added a default label for each bbox
  • Loading branch information
ishvindersethi22 authored Feb 11, 2025
2 parents ee71501 + f25b267 commit b769def
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/ui/pages/container/Label-Studio/AllTaskLSF.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const LabelStudioWrapper = ({annotationNotesRef, loader, showLoader, hideLoader,
useEffect(() => {
getProjectsandTasks(projectId, taskId).then(
([labelConfig, taskData, annotations, predictions]) => {
let sidePanel = labelConfig?.project_type?.includes("OCRSegmentCategorization");
let sidePanel = labelConfig?.project_type?.includes("OCRSegmentCategorization") || labelConfig?.project_type?.includes("OCRTranscriptionEditing");
let showLabelsOnly = labelConfig?.project_type?.includes("OCRSegmentCategorization");
let selectAfterCreateOnly = labelConfig?.project_type?.includes("OCRSegmentCategorization");
let continousLabelingOnly = labelConfig?.project_type?.includes("OCRSegmentCategorization");
Expand Down
18 changes: 11 additions & 7 deletions src/ui/pages/container/Label-Studio/LSF.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import InfoIcon from "@mui/icons-material/Info";
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
import getTaskAssignedUsers from "../../../../utils/getTaskAssignedUsers";
import LightTooltip from "../../component/common/Tooltip";
import { labelConfigJS } from "./labelConfigJSX";
import { addLabelsToBboxes, labelConfigJS } from "./labelConfigJSX";

const filterAnnotations = (
annotations,
Expand Down Expand Up @@ -222,7 +222,7 @@ const LabelStudioWrapper = ({
useEffect(() => {
getProjectsandTasks(projectId, taskId).then(
([labelConfig, taskData, annotations, predictions]) => {
let sidePanel = labelConfig?.project_type?.includes("OCRSegmentCategorization");
let sidePanel = labelConfig?.project_type?.includes("OCRSegmentCategorization") || labelConfig?.project_type?.includes("OCRTranscriptionEditing");
let showLabelsOnly = labelConfig?.project_type?.includes("OCRSegmentCategorization");
let selectAfterCreateOnly = labelConfig?.project_type?.includes("OCRSegmentCategorization");
let continousLabelingOnly = labelConfig?.project_type?.includes("OCRSegmentCategorization");
Expand Down Expand Up @@ -397,6 +397,9 @@ const LabelStudioWrapper = ({
let temp = annotation.serializeAnnotation();
let ids = new Set();
let countLables = 0;
if (projectType.includes("OCRTranscriptionEditing")){
addLabelsToBboxes(temp);
}
temp.map((curr) => {
if(curr.type !== "relation"){
ids.add(curr.id);
Expand Down Expand Up @@ -440,7 +443,7 @@ const LabelStudioWrapper = ({
showLoader();
if (taskData.annotation_status !== "freezed") {
postAnnotation(
annotation.serializeAnnotation(),
temp,
taskData.id,
userData.id,
load_time.current,
Expand Down Expand Up @@ -498,8 +501,10 @@ const LabelStudioWrapper = ({
let temp = annotation.serializeAnnotation();
let ids = new Set();
let countLables = 0;
if (projectType.includes("OCRTranscriptionEditing")){
addLabelsToBboxes(temp);
}
temp.map((curr) => {
// console.log(curr);
if(curr.type !== "relation"){
ids.add(curr.id);
}
Expand Down Expand Up @@ -542,13 +547,12 @@ const LabelStudioWrapper = ({
for (let i = 0; i < annotations.length; i++) {
if (
!annotations[i].result?.length ||
!annotation.serializeAnnotation().length ||
annotation.serializeAnnotation()[0].id ===
!temp.length ||
temp[0].id ===
annotations[i].result[0].id
) {
setAutoSave(false);
showLoader();
let temp = annotation.serializeAnnotation();
for (let i = 0; i < temp.length; i++) {
if(temp[i].type === "relation"){
continue;
Expand Down
9 changes: 5 additions & 4 deletions src/ui/pages/container/Label-Studio/ReviewLSF.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import styles from "./lsf.module.css";
import "./lsf.css";
import { useSelector, useDispatch } from "react-redux";
import { translate } from "../../../../config/localisation";
import { labelConfigJS } from "./labelConfigJSX";
import { addLabelsToBboxes, labelConfigJS } from "./labelConfigJSX";


const StyledMenu = styled((props) => (
Expand Down Expand Up @@ -281,7 +281,7 @@ const LabelStudioWrapper = ({
useEffect(() => {
getProjectsandTasks(projectId, taskId).then(
([labelConfig, taskData, annotations, predictions]) => {
let sidePanel = labelConfig?.project_type?.includes("OCRSegmentCategorization");
let sidePanel = labelConfig?.project_type?.includes("OCRSegmentCategorization") || labelConfig?.project_type?.includes("OCRTranscriptionEditing");
let showLabelsOnly = labelConfig?.project_type?.includes("OCRSegmentCategorization");
let selectAfterCreateOnly = labelConfig?.project_type?.includes("OCRSegmentCategorization");
let continousLabelingOnly = labelConfig?.project_type?.includes("OCRSegmentCategorization");
Expand Down Expand Up @@ -578,7 +578,9 @@ useEffect(() => {
let temp = annotation.serializeAnnotation();
let ids = new Set();
let countLables = 0;
console.log(temp);
if (projectType.includes("OCRTranscriptionEditing")){
addLabelsToBboxes(temp);
}
temp.map((curr) => {
if(curr.type !== "relation"){
ids.add(curr.id);
Expand Down Expand Up @@ -621,7 +623,6 @@ useEffect(() => {
if (taskData.annotation_status !== "freezed") {
setAutoSave(false);
showLoader();
let temp = annotation.serializeAnnotation();

for (let i = 0; i < temp.length; i++) {
if(temp[i].type === "relation"){
Expand Down
9 changes: 6 additions & 3 deletions src/ui/pages/container/Label-Studio/SuperCheckerLSF.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import styles from "./lsf.module.css";
import "./lsf.css";
import { useSelector, useDispatch } from "react-redux";
import { translate } from "../../../../config/localisation";
import { labelConfigJS } from "./labelConfigJSX";
import { addLabelsToBboxes, labelConfigJS } from "./labelConfigJSX";

const StyledMenu = styled((props) => (
<Menu
Expand Down Expand Up @@ -202,7 +202,7 @@ const LabelStudioWrapper = ({
useEffect(() => {
getProjectsandTasks(projectId, taskId).then(
([labelConfig, taskData, annotations, predictions]) => {
let sidePanel = labelConfig?.project_type?.includes("OCRSegmentCategorization");
let sidePanel = labelConfig?.project_type?.includes("OCRSegmentCategorization") || labelConfig?.project_type?.includes("OCRTranscriptionEditing");
let showLabelsOnly = labelConfig?.project_type?.includes("OCRSegmentCategorization");
let selectAfterCreateOnly = labelConfig?.project_type?.includes("OCRSegmentCategorization");
let continousLabelingOnly = labelConfig?.project_type?.includes("OCRSegmentCategorization");
Expand Down Expand Up @@ -399,7 +399,10 @@ useEffect(() => {
onUpdateAnnotation: function (ls, annotation) {
let temp = annotation.serializeAnnotation();
let ids = new Set();
let countLables = 0;
let countLables = 0;
if (projectType.includes("OCRTranscriptionEditing")){
addLabelsToBboxes(temp);
}
temp.map((curr) => {
if(curr.type !== "relation"){
ids.add(curr.id);
Expand Down
37 changes: 37 additions & 0 deletions src/ui/pages/container/Label-Studio/labelConfigJSX.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,40 @@ export const labelConfigJS = `<View>
<Relation value="c" selected="true"/>
</Relations>
</View>`;

export function addLabelsToBboxes(data) {
const bboxIdToLabel = new Map();
data.forEach(item => {
if (item.type === "labels" && item.value.labels) {
const bboxId = item.id;
bboxIdToLabel.set(bboxId, item.value.labels[0]);
}
});

data.forEach(item => {
if (item.type === "rectangle" && !bboxIdToLabel.has(item.id)) {
const labelItem = {
original_width: item.original_width,
original_height: item.original_height,
image_rotation: item.image_rotation,
value: {
x: item.value.x,
y: item.value.y,
width: item.value.width,
height: item.value.height,
rotation: item.value.rotation,
labels: ["Body"]
},
id: item.id,
from_name: "annotation_labels",
to_name: "image_url",
type: "labels",
origin: "manual"
};
data.push(labelItem);
bboxIdToLabel.set(item.id, "Body");
}
});

return data;
}

0 comments on commit b769def

Please sign in to comment.