Skip to content

Commit

Permalink
Merge pull request #17 from areddish/update-3.0
Browse files Browse the repository at this point in the history
[CustomVision] Update to 3.0
  • Loading branch information
wiazur authored Dec 5, 2019
2 parents 1809d72 + 418e0d5 commit a4e1336
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 6 additions & 3 deletions Samples/customvision/customVisionImgClassify.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const predictionKey = process.env[predictionKeyVar];
// Add your Custom Vision endpoint to your environment variables.
const endPoint = process.env['CUSTOM_VISION_ENDPOINT']

const predictionResourceId = "<your prediction resource id>";
const publishIterationName = "classifyModel";

const trainer = new TrainingApiClient(trainingKey, endPoint);

async function sample() {
Expand Down Expand Up @@ -68,14 +71,14 @@ async function sample() {
}
console.log("Training status: " + trainingIteration.status);

trainingIteration.isDefault = true;
await trainer.updateIteration(sampleProject.id, trainingIteration.id, trainingIteration);
// Publish the iteration to the end point
await trainer.publishIteration(sampleProject.id, trainingIteration.id, publishIterationName, predictionResourceId);

// Step 5. Prediction
const predictor = new PredictionApiClient(predictionKey, endPoint);
const testFile = fs.readFileSync(`${sampleDataRoot}/Test/test_image.jpg`);

const results = await predictor.predictImage(sampleProject.id, testFile, { iterationId: trainingIteration.id });
const results = await predictor.classifyImage(sampleProject.id, publishIterationName, testFile);

// Step 6. Show results
console.log("Results:");
Expand Down
9 changes: 6 additions & 3 deletions Samples/customvision/customVisionObjDetect.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const predictionKey = process.env[predictionKeyVar];
// Add your Custom Vision endpoint to your environment variables.
const endPoint = process.env['CUSTOM_VISION_ENDPOINT']

const predictionResourceId = "<your prediction resource id>";
const publishIterationName = "detectModel";

const trainer = new TrainingApi.TrainingAPIClient(trainingKey, endPoint);

async function sample() {
Expand Down Expand Up @@ -146,14 +149,14 @@ async function sample() {
}
console.log("Training status: " + trainingIteration.status);

trainingIteration.isDefault = true;
await trainer.updateIteration(sampleProject.id, trainingIteration.id, trainingIteration);
// Publish the iteration to the end point
await trainer.publishIteration(sampleProject.id, trainingIteration.id, publishIterationName, predictionResourceId);

// Step 5. Prediction
const predictor = new PredictionApi.PredictionAPIClient(predictionKey, endPoint);
const testFile = fs.readFileSync(`${sampleDataRoot}/Test/test_od_image.jpg`);

const results = await predictor.predictImage(sampleProject.id, testFile, { iterationId: trainingIteration.id })
const results = await predictor.detectImage(sampleProject.id, publishIterationName, testFile)

// Step 6. Show results
console.log("Results:");
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
"azure-cognitiveservices-textanalytics": "^3.0.0",
"azure-cognitiveservices-vision": "^1.0.0-preview",
"azure-cognitiveservices-visualsearch": "^1.1.0-preview",
"azure-cognitiveservices-customvision-training": "^3.0.0",
"azure-cognitiveservices-customvision-prediction": "^3.0.0",

"ms-rest": "^2.3.3",
"ms-rest-azure": "^2.5.5",
"npm": "^5.8.0",
Expand Down

0 comments on commit a4e1336

Please sign in to comment.