-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualRecognition_train.js
137 lines (131 loc) · 5.34 KB
/
visualRecognition_train.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
let watson = require(
'C:/Users/IBM_ADMIN/AppData/Roaming/npm/node_modules/watson-developer-cloud'
);
let fs = require('fs');
let visual_recognition = watson.visual_recognition({
api_key: '55c85a4304deb5441e8518a9d0225f7e77809940',
version: 'v3',
version_date: '2016-05-20'
});
let paramsClassify = {
/* images_file --> (Required) The image file (.jpg, or .png) or
compressed (.zip) file of images to classify.
The max number of images in a .zip file is limited to 20,
and limited to 5 MB. */
images_file: fs.createReadStream('sample.jpg'),
/* classifier_ids --> an array contains the visula recognition models,
which may contain user trained model and watson 'default' module
An array of classifier IDs to classify the images against. */
"classifier_ids": ["people_1143812233", "default"],
/* threshold --> A floating point value that specifies
the minimum score a class must have to be displayed in the response. */
"threshold": 0.0
};
/* Classify an image
For each image, the response includes a score
for each class within each selected classifier.
Scores range from 0 - 1 with a higher score indicating
greater likelihood of the class being depicted in the image.
The default threshold for reporting scores from a classifier is 0.5.
We recommend an image that is a minimum of 224 x 224 pixels
for best quality results. */
let imageClassify = visual_recognition.classify(paramsClassify,
function(err,
res) {
if (err)
console.log(err);
else
console.log(JSON.stringify(res, null, 2));
});
/* paramters to classify image */
let paramsClassify = {
/* images_file --> (Required) The image file (.jpg, or .png) or
compressed (.zip) file of images to classify.
The max number of images in a .zip file is limited to 20,
and limited to 5 MB. */
images_file: fs.createReadStream('./resources/li.jpg'),
/* classifier_ids --> an array contains the visula recognition models,
which may contain user trained model and watson 'default' module
An array of classifier IDs to classify the images against. */
"classifier_ids": ["people_1143812233", "default"],
/* threshold --> A floating point value that specifies
the minimum score a class must have to be displayed in the response. */
"threshold": 0.0
};
/* Classify an image
For each image, the response includes a score
for each class within each selected classifier.
Scores range from 0 - 1 with a higher score indicating
greater likelihood of the class being depicted in the image.
The default threshold for reporting scores from a classifier is 0.5.
We recommend an image that is a minimum of 224 x 224 pixels
for best quality results. */
let classifyImage = visual_recognition.classify(paramsClassify, function(err,
res) {
if (err)
console.log(err);
else
console.log(JSON.stringify(res, null, 2));
});
let paramsCreate = {
/* The name of the new classifier.
Cannot contain spaces or special characters. */
name: 'people',
/* {classname}_positive_examples: (Required)
A compressed (.zip) file of images that depict the visual subject
for a class within the new classifier.
Must contain a minimum of 10 images. */
liyang_positive_examples: fs.createReadStream('./resources/liyang.zip'),
zhangxueyou_positive_examples: fs.createReadStream(
'./resources/zhangxueyou.zip'),
/* negative_examples: (Optinal)
A compressed (.zip) file of images that do not depict the visual subject
of any of the classes of the new classifier.
Must contain a minimum of 10 images.*/
negative_examples: fs.createReadStream('./resources/other.zip')
};
/* Train a new multi-faceted classifier on the uploaded image data.
A new custom classifier can be trained by several compressed (.zip) files,
including files containing positive or negative images (.jpg, or .png).
You must supply at least two compressed files,
either two positive example files or one positive and one negative example file.*/
let createClassifier = visual_recognition.createClassifier(paramsCreate,
function(err, response) {
if (err)
console.log(err);
else
console.log(JSON.stringify(response, null, 2));
});
// Retrieve information about a specific classifier.
let getClassifier = visual_recognition.getClassifier({
//Required. The ID of the classifier for which you want details.
classifier_id: 'people_1143812233'
},
function(err, response) {
if (err)
console.log(err);
else
console.log(JSON.stringify(response, null, 2));
}
);
//Delete a custom classifier with the specified classifier ID.
let deleteClassifier = visual_recognition.deleteClassifier({
//The ID of the classifier you want to delete.
classifier_id: 'people_975487466'
},
function(err, response) {
if (err)
console.log(err);
else
console.log(JSON.stringify(response, null, 2));
}
);
//Retrieve a list of user-created classifiers.
let listClassifiers = visual_recognition.listClassifiers({},
function(err, response) {
if (err)
console.log(err);
else
console.log(JSON.stringify(response, null, 2));
}
);