File tree 1 file changed +16
-4
lines changed
1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -35,25 +35,37 @@ export async function load(base = BASE_PATH, options = { size: IMAGE_SIZE }) {
35
35
return nsfwnet
36
36
}
37
37
38
+ interface IOHandler {
39
+ load : ( ) => any
40
+ }
41
+
38
42
export class NSFWJS {
39
43
public endpoints : string [ ]
40
44
41
45
private options : nsfwjsOptions
42
- private path : string
46
+ private pathOrIOHandler : string | IOHandler
43
47
private model : tf . LayersModel
44
48
private intermediateModels : { [ layerName : string ] : tf . LayersModel } = { }
45
49
46
50
private normalizationOffset : tf . Scalar
47
51
48
- constructor ( base : string , options : nsfwjsOptions ) {
52
+ constructor (
53
+ modelPathBaseOrIOHandler : string | IOHandler ,
54
+ options : nsfwjsOptions
55
+ ) {
49
56
this . options = options
50
- this . path = `${ base } model.json`
51
57
this . normalizationOffset = tf . scalar ( 255 )
58
+
59
+ if ( typeof modelPathBaseOrIOHandler === 'string' ) {
60
+ this . pathOrIOHandler = `${ modelPathBaseOrIOHandler } model.json`
61
+ } else {
62
+ this . pathOrIOHandler = modelPathBaseOrIOHandler
63
+ }
52
64
}
53
65
54
66
async load ( ) {
55
67
// this is a Layers Model
56
- this . model = await tf . loadLayersModel ( this . path )
68
+ this . model = await tf . loadLayersModel ( this . pathOrIOHandler )
57
69
this . endpoints = this . model . layers . map ( l => l . name )
58
70
const { size } = this . options
59
71
You can’t perform that action at this time.
0 commit comments