Skip to content

Commit 55aec8c

Browse files
committed
feat(visual-recognition-v4): new method: getModelFile
1 parent 0ccc5bf commit 55aec8c

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

visual-recognition/v4.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,83 @@ class VisualRecognitionV4 extends BaseService {
474474
});
475475
};
476476

477+
/**
478+
* Get a model.
479+
*
480+
* Download a model that you can deploy to detect objects in images. The collection must include a generated model,
481+
* which is indicated in the response for the collection details as `"rscnn_ready": true`. If the value is `false`,
482+
* train or retrain the collection to generate the model.
483+
*
484+
* Currently, the model format is specific to Android apps. For more information about how to deploy the model to your
485+
* app, see the [Watson Visual Recognition on Android](https://github.com/matt-ny/rscnn) project in GitHub.
486+
*
487+
* @param {Object} params - The parameters to send to the service.
488+
* @param {string} params.collectionId - The identifier of the collection.
489+
* @param {string} params.feature - The feature for the model.
490+
* @param {string} params.modelFormat - The format of the returned model.
491+
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
492+
* @param {Function} [callback] - The callback that handles the response
493+
* @returns {Promise<VisualRecognitionV4.Response<NodeJS.ReadableStream|Buffer>>}
494+
*/
495+
public getModelFile(params: VisualRecognitionV4.GetModelFileParams, callback?: VisualRecognitionV4.Callback<NodeJS.ReadableStream|Buffer>): Promise<VisualRecognitionV4.Response<NodeJS.ReadableStream|Buffer>> {
496+
const _params = extend({}, params);
497+
const _callback = callback;
498+
const requiredParams = ['collectionId', 'feature', 'modelFormat'];
499+
500+
return new Promise((resolve, reject) => {
501+
const missingParams = getMissingParams(_params, requiredParams);
502+
if (missingParams) {
503+
if (_callback) {
504+
_callback(missingParams);
505+
return resolve();
506+
}
507+
return reject(missingParams);
508+
}
509+
510+
const query = {
511+
'feature': _params.feature,
512+
'model_format': _params.modelFormat
513+
};
514+
515+
const path = {
516+
'collection_id': _params.collectionId
517+
};
518+
519+
const sdkHeaders = getSdkHeaders(VisualRecognitionV4.DEFAULT_SERVICE_NAME, 'v4', 'getModelFile');
520+
521+
const parameters = {
522+
options: {
523+
url: '/v4/collections/{collection_id}/model',
524+
method: 'GET',
525+
qs: query,
526+
path,
527+
responseType: 'stream',
528+
},
529+
defaultOptions: extend(true, {}, this.baseOptions, {
530+
headers: extend(true, sdkHeaders, {
531+
'Accept': 'application/octet-stream',
532+
}, _params.headers),
533+
}),
534+
};
535+
536+
return this.createRequest(parameters).then(
537+
res => {
538+
if (_callback) {
539+
_callback(null, res);
540+
}
541+
return resolve(res);
542+
},
543+
err => {
544+
if (_callback) {
545+
_callback(err)
546+
return resolve();
547+
}
548+
return reject(err);
549+
}
550+
);
551+
});
552+
};
553+
477554
/*************************
478555
* images
479556
************************/
@@ -1497,6 +1574,29 @@ namespace VisualRecognitionV4 {
14971574
headers?: OutgoingHttpHeaders;
14981575
}
14991576

1577+
/** Parameters for the `getModelFile` operation. */
1578+
export interface GetModelFileParams {
1579+
/** The identifier of the collection. */
1580+
collectionId: string;
1581+
/** The feature for the model. */
1582+
feature: GetModelFileConstants.Feature | string;
1583+
/** The format of the returned model. */
1584+
modelFormat: GetModelFileConstants.ModelFormat | string;
1585+
headers?: OutgoingHttpHeaders;
1586+
}
1587+
1588+
/** Constants for the `getModelFile` operation. */
1589+
export namespace GetModelFileConstants {
1590+
/** The feature for the model. */
1591+
export enum Feature {
1592+
OBJECTS = 'objects',
1593+
}
1594+
/** The format of the returned model. */
1595+
export enum ModelFormat {
1596+
RSCNN = 'rscnn',
1597+
}
1598+
}
1599+
15001600
/** Parameters for the `addImages` operation. */
15011601
export interface AddImagesParams {
15021602
/** The identifier of the collection. */
@@ -1748,6 +1848,7 @@ namespace VisualRecognitionV4 {
17481848
source: ImageSource;
17491849
/** Height and width of an image. */
17501850
dimensions?: ImageDimensions;
1851+
/** Details about the errors. */
17511852
errors?: Error[];
17521853
/** Training data for all objects. */
17531854
training_data?: TrainingDataObjects;
@@ -1849,6 +1950,8 @@ namespace VisualRecognitionV4 {
18491950
data_changed: boolean;
18501951
/** Whether the most recent training failed. */
18511952
latest_failed: boolean;
1953+
/** Whether the model can be downloaded after the training status is `ready`. */
1954+
rscnn_ready: boolean;
18521955
/** Details about the training. If training is in progress, includes information about the status. If training
18531956
* is not in progress, includes a success message or information about why training failed.
18541957
*/

0 commit comments

Comments
 (0)