Skip to content

Commit d6a0594

Browse files
committed
Fix: Enables selection of azure region for custom vision export (microsoft#765)
Adds ability to select azure region where your custom vision service is hosted. Filters domain list by project type Resolves microsoft#759, microsoft#770
1 parent c10c971 commit d6a0594

File tree

18 files changed

+327
-126
lines changed

18 files changed

+327
-126
lines changed

src/common/localization/en-us.ts

+18
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,28 @@ export const english: IAppStrings = {
304304
},
305305
azureCV: {
306306
displayName: "Azure Custom Vision Service",
307+
regions: {
308+
australiaEast: "Australia East",
309+
centralIndia: "Central India",
310+
eastUs: "East US",
311+
eastUs2: "East US 2",
312+
japanEast: "Japan East",
313+
northCentralUs: "North Central US",
314+
northEurope: "North Europe",
315+
southCentralUs: "South Central US",
316+
southeastAsia: "Southeast Asia",
317+
ukSouth: "UK South",
318+
westUs2: "West US 2",
319+
westEurope: "West Europe",
320+
},
307321
properties: {
308322
apiKey: {
309323
title: "API Key",
310324
},
325+
region: {
326+
title: "Region",
327+
description: "The Azure region where your service is deployed",
328+
},
311329
classificationType: {
312330
title: "Classification Type",
313331
options: {

src/common/localization/es-cl.ts

+18
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,28 @@ export const spanish: IAppStrings = {
306306
},
307307
azureCV: {
308308
displayName: "Servicio de Visión Personalizada Azure",
309+
regions: {
310+
australiaEast: "Australia este",
311+
centralIndia: "Centro de la India",
312+
eastUs: "Este de EE.",
313+
eastUs2: "Este US 2",
314+
japanEast: "Japón este",
315+
northCentralUs: "Centro norte de EE.",
316+
northEurope: "Europa del norte",
317+
southCentralUs: "Centro sur de EE.",
318+
southeastAsia: "Sudeste asiático",
319+
ukSouth: "UK sur",
320+
westUs2: "West US 2",
321+
westEurope: "Europa occidental",
322+
},
309323
properties: {
310324
apiKey: {
311325
title: "Clave de API",
312326
},
327+
region: {
328+
title: "Región",
329+
description: "La región de Azure donde se implementa el servicio",
330+
},
313331
classificationType: {
314332
title: "Tipo de clasificación",
315333
options: {

src/common/strings.ts

+18
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,28 @@ export interface IAppStrings {
302302
},
303303
azureCV: {
304304
displayName: string,
305+
regions: {
306+
eastUs: string,
307+
eastUs2: string,
308+
northCentralUs: string,
309+
southCentralUs: string,
310+
westUs2: string,
311+
westEurope: string,
312+
northEurope: string,
313+
southeastAsia: string,
314+
australiaEast: string,
315+
centralIndia: string,
316+
ukSouth: string,
317+
japanEast: string,
318+
},
305319
properties: {
306320
apiKey: {
307321
title: string,
308322
},
323+
region: {
324+
title: string,
325+
description: string,
326+
},
309327
newOrExisting: {
310328
title: string,
311329
options: {

src/providers/export/azureCustomVision.json

+43-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"title": "${strings.export.providers.azureCV.displayName}",
44
"required": [
55
"assetState",
6-
"apiKey"
6+
"apiKey",
7+
"region"
78
],
89
"properties": {
910
"assetState": {
@@ -22,6 +23,40 @@
2223
"${strings.export.providers.common.properties.assetState.options.tagged}"
2324
]
2425
},
26+
"region": {
27+
"type": "string",
28+
"title": "${strings.export.providers.azureCV.properties.region.title}",
29+
"description": "${strings.export.providers.azureCV.properties.region.description}",
30+
"default": "southcentralus",
31+
"enum": [
32+
"australiaeast",
33+
"centralindia",
34+
"eastus",
35+
"eastus2",
36+
"japaneast",
37+
"northcentralus",
38+
"northeurope",
39+
"southcentralus",
40+
"southeastasia",
41+
"uksouth",
42+
"westus2",
43+
"westeurope"
44+
],
45+
"enumNames": [
46+
"${strings.export.providers.azureCV.regions.australiaEast}",
47+
"${strings.export.providers.azureCV.regions.centralIndia}",
48+
"${strings.export.providers.azureCV.regions.eastUs}",
49+
"${strings.export.providers.azureCV.regions.eastUs2}",
50+
"${strings.export.providers.azureCV.regions.japanEast}",
51+
"${strings.export.providers.azureCV.regions.northCentralUs}",
52+
"${strings.export.providers.azureCV.regions.northEurope}",
53+
"${strings.export.providers.azureCV.regions.southCentralUs}",
54+
"${strings.export.providers.azureCV.regions.southeastAsia}",
55+
"${strings.export.providers.azureCV.regions.ukSouth}",
56+
"${strings.export.providers.azureCV.regions.westUs2}",
57+
"${strings.export.providers.azureCV.regions.westEurope}"
58+
]
59+
},
2560
"apiKey": {
2661
"type": "string",
2762
"title": "${strings.export.providers.azureCV.properties.apiKey.title}"
@@ -61,28 +96,28 @@
6196
"projectType": {
6297
"type": "string",
6398
"title": "${strings.export.providers.azureCV.properties.projectType.title}",
99+
"default": "Classification",
64100
"enum": [
65101
"Classification",
66-
"Object Detection"
102+
"ObjectDetection"
67103
],
68104
"enumNames": [
69105
"${strings.export.providers.azureCV.properties.projectType.options.classification}",
70106
"${strings.export.providers.azureCV.properties.projectType.options.objectDetection}"
71-
],
72-
"default": "Classification"
107+
]
73108
},
74109
"classificationType": {
75110
"type": "string",
76111
"title": "${strings.export.providers.azureCV.properties.classificationType.title}",
112+
"default": "Multilabel",
77113
"enum": [
78114
"Multilabel",
79115
"Multiclass"
80116
],
81117
"enumNames": [
82118
"${strings.export.providers.azureCV.properties.classificationType.options.multiLabel}",
83119
"${strings.export.providers.azureCV.properties.classificationType.options.multiClass}"
84-
],
85-
"default": "Multilabel"
120+
]
86121
},
87122
"domainId": {
88123
"type": "string",
@@ -91,6 +126,8 @@
91126
},
92127
"required": [
93128
"name",
129+
"projectType",
130+
"classificationType",
94131
"domainId"
95132
]
96133
},

src/providers/export/azureCustomVision.test.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import shortid from "shortid";
22
import _ from "lodash";
3-
import { AzureCustomVisionProvider, IAzureCustomVisionExportOptions, NewOrExisting } from "./azureCustomVision";
3+
import {
4+
AzureCustomVisionProvider, IAzureCustomVisionExportOptions,
5+
NewOrExisting, AzureRegion,
6+
} from "./azureCustomVision";
47
import registerProviders from "../../registerProviders";
58
import { ExportProviderFactory } from "./exportProviderFactory";
69
import MockFactory from "../../common/mockFactory";
@@ -29,6 +32,7 @@ describe("Azure Custom Vision Export Provider", () => {
2932
let testProject: IProject = null;
3033
const defaultOptions: IAzureCustomVisionExportOptions = {
3134
apiKey: expect.any(String),
35+
region: AzureRegion.SouthCentralUS,
3236
assetState: ExportAssetState.All,
3337
newOrExisting: NewOrExisting.New,
3438
projectId: expect.any(String),
@@ -64,6 +68,7 @@ describe("Azure Custom Vision Export Provider", () => {
6468
assetState: ExportAssetState.All,
6569
projectId: "azure-custom-vision-project-1",
6670
apiKey: "ABC123",
71+
region: AzureRegion.SouthCentralUS,
6772
},
6873
},
6974
};
@@ -81,6 +86,18 @@ describe("Azure Custom Vision Export Provider", () => {
8186
expect(provider).toBeInstanceOf(AzureCustomVisionProvider);
8287
});
8388

89+
it("Constructs custom vision service with correct options", () => {
90+
const customVisionMock = AzureCustomVisionService as jest.Mocked<typeof AzureCustomVisionService>;
91+
const providerOptions = testProject.exportFormat.providerOptions as IAzureCustomVisionExportOptions;
92+
providerOptions.region = AzureRegion.WestEurope;
93+
createProvider(testProject);
94+
95+
expect(customVisionMock).toBeCalledWith({
96+
apiKey: providerOptions.apiKey,
97+
baseUrl: `https://${providerOptions.region}.api.cognitive.microsoft.com/customvision/v2.2/Training`,
98+
});
99+
});
100+
84101
it("Calling save with New project creates Azure Custom Vision project", async () => {
85102
const customVisionMock = AzureCustomVisionService as jest.Mocked<typeof AzureCustomVisionService>;
86103
customVisionMock.prototype.create = jest.fn((project) => {

src/providers/export/azureCustomVision.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import HtmlFileReader from "../../common/htmlFileReader";
1717
export interface IAzureCustomVisionExportOptions extends IExportProviderOptions {
1818
assetState: ExportAssetState;
1919
newOrExisting: NewOrExisting;
20+
region: AzureRegion;
2021
apiKey: string;
2122
projectId?: string;
2223
name?: string;
@@ -38,6 +39,24 @@ export enum NewOrExisting {
3839
Existing = "existing",
3940
}
4041

42+
/**
43+
* Azure regions
44+
*/
45+
export enum AzureRegion {
46+
EastUS = "eastus",
47+
EastUS2 = "eastus2",
48+
NorthCentralUS = "northcentralus",
49+
SouthCentralUS = "southcentralus",
50+
WestUS2 = "westus2",
51+
WestEurope = "westeurope",
52+
NorthEurope = "northeurope",
53+
SoutheastAsia = "southeastasia",
54+
AustraliaEast = "australiaeast",
55+
CentralIndia = "centralindia",
56+
UKSouth = "uksouth",
57+
JapanEast = "japaneast",
58+
}
59+
4160
/**
4261
* @name - Azure Custom Vision Provider
4362
* @description - Exports a VoTT project into an Azure custom vision project
@@ -49,9 +68,13 @@ export class AzureCustomVisionProvider extends ExportProvider<IAzureCustomVision
4968
super(project, options);
5069
Guard.null(options);
5170

71+
if (!options.region) {
72+
options.region = AzureRegion.SouthCentralUS;
73+
}
74+
5275
const cusomVisionServiceOptions: IAzureCustomVisionServiceOptions = {
5376
apiKey: options.apiKey,
54-
baseUrl: "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.2/Training",
77+
baseUrl: `https://${options.region}.api.cognitive.microsoft.com/customvision/v2.2/Training`,
5578
};
5679
this.customVisionService = new AzureCustomVisionService(cusomVisionServiceOptions);
5780
}
@@ -111,6 +134,7 @@ export class AzureCustomVisionProvider extends ExportProvider<IAzureCustomVision
111134

112135
return {
113136
assetState: customVisionOptions.assetState,
137+
region: customVisionOptions.region,
114138
apiKey: customVisionOptions.apiKey,
115139
projectId: customVisionProject.id,
116140
newOrExisting: NewOrExisting.Existing,

src/providers/export/azureCustomVision.ui.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"ui:widget": "externalPicker",
1010
"ui:options": {
1111
"method": "GET",
12-
"url": "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.2/Training/projects",
12+
"url": "https://${props.formContext.providerOptions.region}.api.cognitive.microsoft.com/customvision/v2.2/Training/projects",
1313
"authHeaderName": "Training-key",
1414
"authHeaderValue": "${props.formContext.providerOptions.apiKey}",
1515
"keySelector": "${item.id}",
@@ -20,11 +20,16 @@
2020
"ui:widget": "externalPicker",
2121
"ui:options": {
2222
"method": "GET",
23-
"url": "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.2/Training/domains",
23+
"url": "https://${props.formContext.providerOptions.region}.api.cognitive.microsoft.com/customvision/v2.2/Training/domains",
2424
"authHeaderName": "Training-key",
2525
"authHeaderValue": "${props.formContext.providerOptions.apiKey}",
2626
"keySelector": "${item.id}",
27-
"valueSelector": "${item.name}"
27+
"valueSelector": "${item.name}",
28+
"filter": {
29+
"left": "${item.type}",
30+
"operator": "eq",
31+
"right": "${props.formContext.providerOptions.projectType}"
32+
}
2833
}
2934
}
3035
}

0 commit comments

Comments
 (0)