How infinitered/nsfwjs works
NSFWJS is a JavaScript image-classification library: callers load a bundled or hosted TensorFlow.js model, submit an image for classification, and receive ranked probabilities across five content classes. The graph separates the public entry point, model registry and definitions, and model data. The README documents hosted models, caching, and multiple backends; source excerpts show the load, inference, and classification implementation. Some internal loading details are omitted from the excerpts, so only documented or directly evidenced relationships are drawn.
Main entry points: default_models.ts Default registry · core.ts Load and classify · index.ts Public load API · models Bundled model files
Components 14
Library API
- Public load API
src/index.ts
Model Catalog
- Default registry
src/default_models.ts - MobileNetV2 definition
src/models/mobilenet_v2.ts - MobileNetV2Mid definition
src/models/mobilenet_v2_mid.ts - InceptionV3 definition
src/models/inception_v3.ts - MobileNetV2 loaders
src/model_imports/mobilenet_v2.ts - MobileNetV2Mid loaders
src/model_imports/mobilenet_v2_mid.ts - InceptionV3 loaders
src/model_imports/inception_v3.ts - Bundled model files
models
Inference Runtime
- Load and classify
src/core.ts - Class labels
src/nsfw_classes.ts
Other components
- Application
- TensorFlow.js
- Hosted model files
Connections 16
- Application → Public load API: calls load
README.md - Public load API → Default registry: selects defaults
src/index.ts - Public load API → Load and classify: delegates load
src/index.ts - Default registry → MobileNetV2 definition: registers
src/default_models.ts - Default registry → MobileNetV2Mid definition: registers
src/default_models.ts - Default registry → InceptionV3 definition: registers
src/default_models.ts - MobileNetV2 definition → MobileNetV2 loaders: uses loaders
src/models/mobilenet_v2.ts - MobileNetV2Mid definition → MobileNetV2Mid loaders: uses loaders
src/models/mobilenet_v2_mid.ts - InceptionV3 definition → InceptionV3 loaders: uses loaders
src/models/inception_v3.ts - MobileNetV2 loaders → Bundled model files: loads shards
src/model_imports/mobilenet_v2.ts - MobileNetV2Mid loaders → Bundled model files: loads shards
src/model_imports/mobilenet_v2_mid.ts - InceptionV3 loaders → Bundled model files: loads shards
src/model_imports/inception_v3.ts - Load and classify → TensorFlow.js: loads and predicts
README.md - Load and classify → Class labels: uses labels
src/core.ts - Application → Load and classify: classifies image
README.md - Application → Hosted model files: provides model URL
README.md