Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Commit

Permalink
Fix: Enables selection of azure region for custom vision export (#765)
Browse files Browse the repository at this point in the history
Adds ability to select azure region where your custom vision service is hosted.
Filters domain list by project type

Resolves #759, #770
  • Loading branch information
wbreza committed Apr 29, 2019
1 parent c10c971 commit d6a0594
Show file tree
Hide file tree
Showing 18 changed files with 327 additions and 126 deletions.
18 changes: 18 additions & 0 deletions src/common/localization/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,28 @@ export const english: IAppStrings = {
},
azureCV: {
displayName: "Azure Custom Vision Service",
regions: {
australiaEast: "Australia East",
centralIndia: "Central India",
eastUs: "East US",
eastUs2: "East US 2",
japanEast: "Japan East",
northCentralUs: "North Central US",
northEurope: "North Europe",
southCentralUs: "South Central US",
southeastAsia: "Southeast Asia",
ukSouth: "UK South",
westUs2: "West US 2",
westEurope: "West Europe",
},
properties: {
apiKey: {
title: "API Key",
},
region: {
title: "Region",
description: "The Azure region where your service is deployed",
},
classificationType: {
title: "Classification Type",
options: {
Expand Down
18 changes: 18 additions & 0 deletions src/common/localization/es-cl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,28 @@ export const spanish: IAppStrings = {
},
azureCV: {
displayName: "Servicio de Visión Personalizada Azure",
regions: {
australiaEast: "Australia este",
centralIndia: "Centro de la India",
eastUs: "Este de EE.",
eastUs2: "Este US 2",
japanEast: "Japón este",
northCentralUs: "Centro norte de EE.",
northEurope: "Europa del norte",
southCentralUs: "Centro sur de EE.",
southeastAsia: "Sudeste asiático",
ukSouth: "UK sur",
westUs2: "West US 2",
westEurope: "Europa occidental",
},
properties: {
apiKey: {
title: "Clave de API",
},
region: {
title: "Región",
description: "La región de Azure donde se implementa el servicio",
},
classificationType: {
title: "Tipo de clasificación",
options: {
Expand Down
18 changes: 18 additions & 0 deletions src/common/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,28 @@ export interface IAppStrings {
},
azureCV: {
displayName: string,
regions: {
eastUs: string,
eastUs2: string,
northCentralUs: string,
southCentralUs: string,
westUs2: string,
westEurope: string,
northEurope: string,
southeastAsia: string,
australiaEast: string,
centralIndia: string,
ukSouth: string,
japanEast: string,
},
properties: {
apiKey: {
title: string,
},
region: {
title: string,
description: string,
},
newOrExisting: {
title: string,
options: {
Expand Down
49 changes: 43 additions & 6 deletions src/providers/export/azureCustomVision.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"title": "${strings.export.providers.azureCV.displayName}",
"required": [
"assetState",
"apiKey"
"apiKey",
"region"
],
"properties": {
"assetState": {
Expand All @@ -22,6 +23,40 @@
"${strings.export.providers.common.properties.assetState.options.tagged}"
]
},
"region": {
"type": "string",
"title": "${strings.export.providers.azureCV.properties.region.title}",
"description": "${strings.export.providers.azureCV.properties.region.description}",
"default": "southcentralus",
"enum": [
"australiaeast",
"centralindia",
"eastus",
"eastus2",
"japaneast",
"northcentralus",
"northeurope",
"southcentralus",
"southeastasia",
"uksouth",
"westus2",
"westeurope"
],
"enumNames": [
"${strings.export.providers.azureCV.regions.australiaEast}",
"${strings.export.providers.azureCV.regions.centralIndia}",
"${strings.export.providers.azureCV.regions.eastUs}",
"${strings.export.providers.azureCV.regions.eastUs2}",
"${strings.export.providers.azureCV.regions.japanEast}",
"${strings.export.providers.azureCV.regions.northCentralUs}",
"${strings.export.providers.azureCV.regions.northEurope}",
"${strings.export.providers.azureCV.regions.southCentralUs}",
"${strings.export.providers.azureCV.regions.southeastAsia}",
"${strings.export.providers.azureCV.regions.ukSouth}",
"${strings.export.providers.azureCV.regions.westUs2}",
"${strings.export.providers.azureCV.regions.westEurope}"
]
},
"apiKey": {
"type": "string",
"title": "${strings.export.providers.azureCV.properties.apiKey.title}"
Expand Down Expand Up @@ -61,28 +96,28 @@
"projectType": {
"type": "string",
"title": "${strings.export.providers.azureCV.properties.projectType.title}",
"default": "Classification",
"enum": [
"Classification",
"Object Detection"
"ObjectDetection"
],
"enumNames": [
"${strings.export.providers.azureCV.properties.projectType.options.classification}",
"${strings.export.providers.azureCV.properties.projectType.options.objectDetection}"
],
"default": "Classification"
]
},
"classificationType": {
"type": "string",
"title": "${strings.export.providers.azureCV.properties.classificationType.title}",
"default": "Multilabel",
"enum": [
"Multilabel",
"Multiclass"
],
"enumNames": [
"${strings.export.providers.azureCV.properties.classificationType.options.multiLabel}",
"${strings.export.providers.azureCV.properties.classificationType.options.multiClass}"
],
"default": "Multilabel"
]
},
"domainId": {
"type": "string",
Expand All @@ -91,6 +126,8 @@
},
"required": [
"name",
"projectType",
"classificationType",
"domainId"
]
},
Expand Down
19 changes: 18 additions & 1 deletion src/providers/export/azureCustomVision.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import shortid from "shortid";
import _ from "lodash";
import { AzureCustomVisionProvider, IAzureCustomVisionExportOptions, NewOrExisting } from "./azureCustomVision";
import {
AzureCustomVisionProvider, IAzureCustomVisionExportOptions,
NewOrExisting, AzureRegion,
} from "./azureCustomVision";
import registerProviders from "../../registerProviders";
import { ExportProviderFactory } from "./exportProviderFactory";
import MockFactory from "../../common/mockFactory";
Expand Down Expand Up @@ -29,6 +32,7 @@ describe("Azure Custom Vision Export Provider", () => {
let testProject: IProject = null;
const defaultOptions: IAzureCustomVisionExportOptions = {
apiKey: expect.any(String),
region: AzureRegion.SouthCentralUS,
assetState: ExportAssetState.All,
newOrExisting: NewOrExisting.New,
projectId: expect.any(String),
Expand Down Expand Up @@ -64,6 +68,7 @@ describe("Azure Custom Vision Export Provider", () => {
assetState: ExportAssetState.All,
projectId: "azure-custom-vision-project-1",
apiKey: "ABC123",
region: AzureRegion.SouthCentralUS,
},
},
};
Expand All @@ -81,6 +86,18 @@ describe("Azure Custom Vision Export Provider", () => {
expect(provider).toBeInstanceOf(AzureCustomVisionProvider);
});

it("Constructs custom vision service with correct options", () => {
const customVisionMock = AzureCustomVisionService as jest.Mocked<typeof AzureCustomVisionService>;
const providerOptions = testProject.exportFormat.providerOptions as IAzureCustomVisionExportOptions;
providerOptions.region = AzureRegion.WestEurope;
createProvider(testProject);

expect(customVisionMock).toBeCalledWith({
apiKey: providerOptions.apiKey,
baseUrl: `https://${providerOptions.region}.api.cognitive.microsoft.com/customvision/v2.2/Training`,
});
});

it("Calling save with New project creates Azure Custom Vision project", async () => {
const customVisionMock = AzureCustomVisionService as jest.Mocked<typeof AzureCustomVisionService>;
customVisionMock.prototype.create = jest.fn((project) => {
Expand Down
26 changes: 25 additions & 1 deletion src/providers/export/azureCustomVision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import HtmlFileReader from "../../common/htmlFileReader";
export interface IAzureCustomVisionExportOptions extends IExportProviderOptions {
assetState: ExportAssetState;
newOrExisting: NewOrExisting;
region: AzureRegion;
apiKey: string;
projectId?: string;
name?: string;
Expand All @@ -38,6 +39,24 @@ export enum NewOrExisting {
Existing = "existing",
}

/**
* Azure regions
*/
export enum AzureRegion {
EastUS = "eastus",
EastUS2 = "eastus2",
NorthCentralUS = "northcentralus",
SouthCentralUS = "southcentralus",
WestUS2 = "westus2",
WestEurope = "westeurope",
NorthEurope = "northeurope",
SoutheastAsia = "southeastasia",
AustraliaEast = "australiaeast",
CentralIndia = "centralindia",
UKSouth = "uksouth",
JapanEast = "japaneast",
}

/**
* @name - Azure Custom Vision Provider
* @description - Exports a VoTT project into an Azure custom vision project
Expand All @@ -49,9 +68,13 @@ export class AzureCustomVisionProvider extends ExportProvider<IAzureCustomVision
super(project, options);
Guard.null(options);

if (!options.region) {
options.region = AzureRegion.SouthCentralUS;
}

const cusomVisionServiceOptions: IAzureCustomVisionServiceOptions = {
apiKey: options.apiKey,
baseUrl: "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.2/Training",
baseUrl: `https://${options.region}.api.cognitive.microsoft.com/customvision/v2.2/Training`,
};
this.customVisionService = new AzureCustomVisionService(cusomVisionServiceOptions);
}
Expand Down Expand Up @@ -111,6 +134,7 @@ export class AzureCustomVisionProvider extends ExportProvider<IAzureCustomVision

return {
assetState: customVisionOptions.assetState,
region: customVisionOptions.region,
apiKey: customVisionOptions.apiKey,
projectId: customVisionProject.id,
newOrExisting: NewOrExisting.Existing,
Expand Down
11 changes: 8 additions & 3 deletions src/providers/export/azureCustomVision.ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"ui:widget": "externalPicker",
"ui:options": {
"method": "GET",
"url": "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.2/Training/projects",
"url": "https://${props.formContext.providerOptions.region}.api.cognitive.microsoft.com/customvision/v2.2/Training/projects",
"authHeaderName": "Training-key",
"authHeaderValue": "${props.formContext.providerOptions.apiKey}",
"keySelector": "${item.id}",
Expand All @@ -20,11 +20,16 @@
"ui:widget": "externalPicker",
"ui:options": {
"method": "GET",
"url": "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.2/Training/domains",
"url": "https://${props.formContext.providerOptions.region}.api.cognitive.microsoft.com/customvision/v2.2/Training/domains",
"authHeaderName": "Training-key",
"authHeaderValue": "${props.formContext.providerOptions.apiKey}",
"keySelector": "${item.id}",
"valueSelector": "${item.name}"
"valueSelector": "${item.name}",
"filter": {
"left": "${item.type}",
"operator": "eq",
"right": "${props.formContext.providerOptions.projectType}"
}
}
}
}
Loading

0 comments on commit d6a0594

Please sign in to comment.