@@ -1116,67 +1116,101 @@ describe('Pipelines', () => {
1116
1116
let detector = await pipeline ( 'object-detection' , m ( models [ 0 ] ) ) ;
1117
1117
1118
1118
// TODO add batched test cases when supported
1119
- let url = 'https://huggingface.co/datasets/mishig/sample_images /resolve/main/savanna .jpg' ;
1120
- let urls = [ 'https://huggingface.co/datasets/mishig/sample_images /resolve/main/airport .jpg' ]
1119
+ let url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs /resolve/main/cats .jpg' ;
1120
+ let urls = [ 'https://huggingface.co/datasets/Xenova/transformers.js-docs /resolve/main/savanna .jpg' ]
1121
1121
1122
1122
// single + threshold
1123
1123
{
1124
1124
let output = await detector ( url , {
1125
1125
threshold : 0.9 ,
1126
1126
} ) ;
1127
1127
1128
- // let expected = {
1129
- // "boxes": [
1130
- // [352.8210112452507, 247.36732184886932, 390.5271676182747, 318.09066116809845],
1131
- // [111.15852802991867, 235.34255504608154, 224.96717244386673, 325.21119117736816],
1132
- // [13.524770736694336, 146.81672930717468, 207.97560095787048, 278.6452639102936],
1133
- // [187.396682202816, 227.97491312026978, 313.05202156305313, 300.26460886001587],
1134
- // [201.60082161426544, 230.86223602294922, 312.1393972635269, 306.5505266189575],
1135
- // [365.85242718458176, 95.3144109249115, 526.5485098958015, 313.17670941352844]
1136
- // ],
1137
- // "classes": [24, 24, 25, 24, 24, 25],
1138
- // "scores": [0.9989480376243591, 0.9990893006324768, 0.9690554738044739, 0.9274907112121582, 0.9714975953102112, 0.9989491105079651],
1139
- // "labels": ["zebra", "zebra", "giraffe", "zebra", "zebra", "giraffe"]
1140
- // };
1141
-
1142
- let num_classes = output . boxes . length ;
1143
- expect ( num_classes ) . toBeGreaterThan ( 1 ) ;
1144
- expect ( output . classes . length ) . toEqual ( num_classes ) ;
1145
- expect ( output . scores . length ) . toEqual ( num_classes ) ;
1146
- expect ( output . labels . length ) . toEqual ( num_classes ) ;
1128
+ // let expected = [
1129
+ // {
1130
+ // "score": 0.9977124929428101,
1131
+ // "label": "remote",
1132
+ // "box": { "xmin": 41, "ymin": 70, "xmax": 176, "ymax": 118 }
1133
+ // },
1134
+ // {
1135
+ // "score": 0.9984639883041382,
1136
+ // "label": "remote",
1137
+ // "box": { "xmin": 332, "ymin": 73, "xmax": 369, "ymax": 188 }
1138
+ // },
1139
+ // {
1140
+ // "score": 0.9964856505393982,
1141
+ // "label": "couch",
1142
+ // "box": { "xmin": 0, "ymin": 1, "xmax": 639, "ymax": 474 }
1143
+ // },
1144
+ // {
1145
+ // "score": 0.9988334774971008,
1146
+ // "label": "cat",
1147
+ // "box": { "xmin": 11, "ymin": 51, "xmax": 314, "ymax": 472 }
1148
+ // },
1149
+ // {
1150
+ // "score": 0.9982513785362244,
1151
+ // "label": "cat",
1152
+ // "box": { "xmin": 345, "ymin": 22, "xmax": 640, "ymax": 371 }
1153
+ // }
1154
+ // ]
1147
1155
1156
+ expect ( output . length ) . toBeGreaterThan ( 0 ) ;
1157
+ for ( let cls of output ) {
1158
+ expect ( typeof cls . score ) . toBe ( 'number' ) ;
1159
+ expect ( typeof cls . label ) . toBe ( 'string' ) ;
1160
+ for ( let key of [ 'xmin' , 'ymin' , 'xmax' , 'ymax' ] ) {
1161
+ expect ( typeof cls . box [ key ] ) . toBe ( 'number' ) ;
1162
+ }
1163
+ }
1148
1164
}
1149
1165
1150
- // single + threshold + percentage
1166
+ // batched + threshold + percentage
1151
1167
{
1152
1168
let output = await detector ( urls , {
1153
1169
threshold : 0.9 ,
1154
1170
percentage : true
1155
1171
} ) ;
1172
+ // let expected = [[
1173
+ // {
1174
+ // score: 0.9991137385368347,
1175
+ // label: 'zebra',
1176
+ // box: { xmin: 0.65165576338768, ymin: 0.685152679681778, xmax: 0.723189502954483, ymax: 0.8801506459712982 }
1177
+ // },
1178
+ // {
1179
+ // score: 0.998811662197113,
1180
+ // label: 'zebra',
1181
+ // box: { xmin: 0.20797613263130188, ymin: 0.6543092578649521, xmax: 0.4147692620754242, ymax: 0.9040975719690323 }
1182
+ // },
1183
+ // {
1184
+ // score: 0.9707837104797363,
1185
+ // label: 'giraffe',
1186
+ // box: { xmin: 0.02498096227645874, ymin: 0.40549489855766296, xmax: 0.38669759035110474, ymax: 0.7895723879337311 }
1187
+ // },
1188
+ // {
1189
+ // score: 0.9984336495399475,
1190
+ // label: 'zebra',
1191
+ // box: { xmin: 0.3540637195110321, ymin: 0.6370827257633209, xmax: 0.5765090882778168, ymax: 0.8480959832668304 }
1192
+ // },
1193
+ // {
1194
+ // score: 0.9986463785171509,
1195
+ // label: 'giraffe',
1196
+ // box: { xmin: 0.6763969212770462, ymin: 0.25748637318611145, xmax: 0.974339172244072, ymax: 0.8684568107128143 }
1197
+ // }
1198
+ // ]]
1199
+
1200
+ expect ( output ) . toHaveLength ( urls . length ) ; // Same number of inputs as outputs
1201
+
1202
+ for ( let i = 0 ; i < output . length ; ++ i ) {
1203
+ expect ( output [ i ] . length ) . toBeGreaterThan ( 0 ) ;
1204
+ for ( let cls of output [ i ] ) {
1205
+ expect ( typeof cls . score ) . toBe ( 'number' ) ;
1206
+ expect ( typeof cls . label ) . toBe ( 'string' ) ;
1207
+ for ( let key of [ 'xmin' , 'ymin' , 'xmax' , 'ymax' ] ) {
1208
+ expect ( typeof cls . box [ key ] ) . toBe ( 'number' ) ;
1209
+ }
1210
+ }
1211
+ }
1212
+
1156
1213
1157
- // let expected = [{
1158
- // "boxes": [
1159
- // [0.7231650948524475, 0.32641804218292236, 0.981127917766571, 0.9918863773345947],
1160
- // [0.7529061436653137, 0.52558633685112, 0.8229959607124329, 0.6482008993625641],
1161
- // [0.5080368518829346, 0.5156279355287552, 0.5494132041931152, 0.5434067696332932],
1162
- // [0.33636586368083954, 0.5217841267585754, 0.3535611182451248, 0.6151944994926453],
1163
- // [0.42090220749378204, 0.4482414871454239, 0.5515891760587692, 0.5207531303167343],
1164
- // [0.1988394856452942, 0.41224047541618347, 0.45213085412979126, 0.5206181704998016],
1165
- // [0.5063001662492752, 0.5170856416225433, 0.5478668659925461, 0.54373899102211],
1166
- // [0.5734506398439407, 0.4508090913295746, 0.7049560993909836, 0.6252130568027496],
1167
- // ],
1168
- // "classes": [6, 1, 8, 1, 5, 5, 3, 6],
1169
- // "scores": [0.9970788359642029, 0.996989905834198, 0.9505048990249634, 0.9984546899795532, 0.9942372441291809, 0.9989550709724426, 0.938920259475708, 0.9992448091506958],
1170
- // "labels": ["bus", "person", "truck", "person", "airplane", "airplane", "car", "bus"]
1171
- // }];
1172
-
1173
- expect ( output ) . toHaveLength ( urls . length ) ;
1174
-
1175
- let num_classes = output [ 0 ] . boxes . length ;
1176
- expect ( num_classes ) . toBeGreaterThan ( 1 ) ;
1177
- expect ( output [ 0 ] . classes . length ) . toEqual ( num_classes ) ;
1178
- expect ( output [ 0 ] . scores . length ) . toEqual ( num_classes ) ;
1179
- expect ( output [ 0 ] . labels . length ) . toEqual ( num_classes ) ;
1180
1214
}
1181
1215
1182
1216
await detector . dispose ( ) ;
0 commit comments