Skip to content

Commit

Permalink
Starain chen/clean autolabel data while training (#712)
Browse files Browse the repository at this point in the history
* add logical to clean auto-label data while training

* 1. remove clear data confirm logical 2. change logical to clean old data

Co-authored-by: Alex Chen <68627897+yongbing-chen@users.noreply.github.com>
  • Loading branch information
starain-pactera and yongbing-chen authored Nov 6, 2020
1 parent 282d557 commit 32cfaea
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/common/localization/es-cl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ export const spanish: IAppStrings = {
addName: "Agregar nombre de modelo ...",
downloadJson: "Descargar archivo JSON",
trainConfirm: {
title: "Etiquetas no revisadas todavía",
message: "Hay archivos recientemente etiquetados automáticamente que aún no ha revisado, ¿desea entrenar con esos archivos?"
title: "Etiquetas aún no revisadas",
message: "Hay archivos recién etiquetados automáticamente aún no revisados por usted, ¿quieres entrenar con esos archivos?"
},
errors: {
electron: {
Expand Down
48 changes: 39 additions & 9 deletions src/react/components/pages/train/trainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import IProjectActions, * as projectActions from "../../../../redux/actions/proj
import IApplicationActions, * as applicationActions from "../../../../redux/actions/applicationActions";
import IAppTitleActions, * as appTitleActions from "../../../../redux/actions/appTitleActions";
import {
IApplicationState, IConnection, IProject, IAppSettings, FieldType, IRecentModel, AssetLabelingState,
IApplicationState, IConnection, IProject, IAppSettings, FieldType, IRecentModel, AssetLabelingState, IAssetMetadata,
} from "../../../../models/applicationState";
import TrainChart from "./trainChart";
import TrainPanel from "./trainPanel";
Expand Down Expand Up @@ -83,7 +83,6 @@ function mapDispatchToProps(dispatch) {
export default class TrainPage extends React.Component<ITrainPageProps, ITrainPageState> {
private appInsights: any = null;
private notAdjustedLabelsConfirm: React.RefObject<Confirm> = React.createRef();

constructor(props) {
super(props);

Expand Down Expand Up @@ -316,12 +315,6 @@ export default class TrainPage extends React.Component<ITrainPageProps, ITrainPa
});

this.trainProcess().then(async (trainResult) => {
this.setState((prevState, props) => ({
isTraining: false,
trainMessage: this.getTrainMessage(trainResult),
currTrainRecord: this.getProjectTrainRecord(),
modelName: "",
}));
const assets = Object.values(this.props.project.assets);
const assetService = new AssetService(this.props.project);
for (const asset of assets) {
Expand All @@ -333,6 +326,12 @@ export default class TrainPage extends React.Component<ITrainPageProps, ITrainPa
await assetService.save({ ...metadata });
}
}
this.setState((prevState, props) => ({
isTraining: false,
trainMessage: this.getTrainMessage(trainResult),
currTrainRecord: this.getProjectTrainRecord(),
modelName: "",
}));
// reset localStorage successful train process
localStorage.setItem("trainPage_inputs", "{}");
}).catch((err) => {
Expand Down Expand Up @@ -367,7 +366,7 @@ export default class TrainPage extends React.Component<ITrainPageProps, ITrainPa
showTrainingFailedWarning: true,
trainingFailedMessage: isOnPrem ? interpolate(strings.train.errors.electron.cantAccessFiles, { folderUri: this.state.inputtedLabelFolderURL }) :
error?.message !== undefined
? error.message : error,
? error.message : error,
});
}
}
Expand All @@ -389,6 +388,7 @@ export default class TrainPage extends React.Component<ITrainPageProps, ITrainPa
trainSourceURL = provider.sas;
trainPrefix = this.props.project.folderPath ? this.props.project.folderPath : "";
}
await this.cleanLabelData();
const payload = {
source: trainSourceURL,
sourceFilter: {
Expand All @@ -411,6 +411,36 @@ export default class TrainPage extends React.Component<ITrainPageProps, ITrainPa
ServiceHelper.handleServiceError(err);
}
}
private async cleanLabelData() {
const allAssets = { ...this.props.project.assets };
await Object.values(allAssets)
.filter(asset => asset.labelingState !== AssetLabelingState.Trained)
.forEachAsync(async (asset) => {
const assetMetadata: IAssetMetadata = { ...await this.props.actions.loadAssetMetadata(this.props.project, asset) };
if (assetMetadata.asset.labelingState === AssetLabelingState.ManuallyLabeled
&& assetMetadata.labelData?.labels?.findIndex(label => label.confidence
|| label.originValue
|| label.revised
|| label.value?.findIndex(item => item["confidence"]) < 0) < 0
) {
return;
}
assetMetadata.asset.labelingState = AssetLabelingState.ManuallyLabeled;
if (assetMetadata.labelData) {
assetMetadata.labelData.labelingState = AssetLabelingState.ManuallyLabeled;
}

assetMetadata.labelData?.labels?.forEach((label) => {
delete label.confidence;
delete label.originValue;
delete label.revised;
label.value?.forEach(item => {
delete item["confidence"];
});
});
await this.props.actions.saveAssetMetadata(this.props.project,assetMetadata);
});
}

private async getTrainStatus(operationLocation: string): Promise<any> {
const timeoutPerFileInMs = 10000; // 10 second for each file
Expand Down
5 changes: 2 additions & 3 deletions src/services/assetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import _ from "lodash";
import Guard from "../common/guard";
import {
IAsset, AssetType, IProject, IAssetMetadata, AssetState,
ILabelData, ILabel, AssetLabelingState
ILabelData, ILabel, AssetLabelingState, IFormRegion
} from "../models/applicationState";
import { AssetProviderFactory, IAssetProvider } from "../providers/storage/assetProviderFactory";
import { StorageProviderFactory, IStorageProvider } from "../providers/storage/storageProviderFactory";
Expand Down Expand Up @@ -85,13 +85,12 @@ export class AssetService {
return result;
};
const getLabelValues = (field: any) => {
return field.elements.map((path: string) => {
return field.elements.map((path: string):IFormRegion => {
const pathArr = path.split('/').slice(1);
const word = pathArr.reduce((obj: any, key: string) => obj[key], { ...predictResults.analyzeResult });
return {
page: field.page,
text: word.text || word.state,
confidence: word.confidence,
boundingBoxes: [getBoundingBox(field.page, word.boundingBox)]
};
});
Expand Down

0 comments on commit 32cfaea

Please sign in to comment.