@cornerstonejs/ai 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +93 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Open Health Imaging Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Cornerstone AI Client Package
|
|
2
|
+
|
|
3
|
+
This package provides AI interfaces for use with Cornerstone in client-side applications. It is designed to support the use of ONNX models, ensuring a clean separation between server-side AI processing and client-specific functionalities tied to Cornerstone.
|
|
4
|
+
|
|
5
|
+
## Key Features
|
|
6
|
+
|
|
7
|
+
- **ONNX Runtime Web Integration**: The package leverages the ONNX Runtime Web library, enabling AI models to run directly in the browser without relying on server-side execution.
|
|
8
|
+
- **Initial Model - Segment Anything Model (SAM)**: Our first supported model is the Segment Anything Model (SAM) https://segment-anything.com/, designed for segmentation tasks.
|
|
9
|
+
|
|
10
|
+
## Getting Started
|
|
11
|
+
|
|
12
|
+
### Running the Example
|
|
13
|
+
|
|
14
|
+
To see the package in action with the Segment Anything Model, use the following command:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
yarn run example segmentAnythingClientSide
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
This will load the SAM model in the browser and allow you to perform segmentation tasks on images.
|
|
21
|
+
|
|
22
|
+
### Model Files
|
|
23
|
+
|
|
24
|
+
The package does not include model binaries due to their size and to give users the flexibility to use their own models. You can download pre-trained model binaries from the following links:
|
|
25
|
+
|
|
26
|
+
Base model (vit_b) - 178 MB compressed
|
|
27
|
+
|
|
28
|
+
- https://ohif-assets-new.s3.us-east-1.amazonaws.com/SAM/sam_b.zip
|
|
29
|
+
|
|
30
|
+
Large model (vit_l) - 1.16 GB compressed
|
|
31
|
+
|
|
32
|
+
- https://ohif-assets-new.s3.us-east-1.amazonaws.com/SAM/sam_l.zip
|
|
33
|
+
|
|
34
|
+
Huge model (vit_h) - 2.38 GB compressed
|
|
35
|
+
|
|
36
|
+
- https://ohif-assets-new.s3.us-east-1.amazonaws.com/SAM/sam_h.zip
|
|
37
|
+
|
|
38
|
+
For the examples we are using the model url and fetch it from the web. If you see in example code we have:
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
#### URL to the model files
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
const models = {
|
|
45
|
+
sam_b: [
|
|
46
|
+
{
|
|
47
|
+
name: 'sam-b-encoder',
|
|
48
|
+
url: 'https://huggingface.co/schmuell/sam-b-fp16/resolve/main/sam_vit_b_01ec64.encoder-fp16.onnx',
|
|
49
|
+
size: 180,
|
|
50
|
+
key: 'encoder',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'sam-b-decoder',
|
|
54
|
+
url: 'https://huggingface.co/schmuell/sam-b-fp16/resolve/main/sam_vit_b_01ec64.decoder.onnx',
|
|
55
|
+
size: 17,
|
|
56
|
+
key: 'decoder',
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const ai = new ONNXSegmentationController({
|
|
62
|
+
listeners: [mlLogger],
|
|
63
|
+
models,
|
|
64
|
+
modelName: 'sam_b',
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
which gives the url to the model files.
|
|
69
|
+
|
|
70
|
+
#### Models in binary
|
|
71
|
+
|
|
72
|
+
You can download the model files and use them offline by moving them to the public folder.
|
|
73
|
+
|
|
74
|
+
In Webpack you can add the model files to the public folder like this
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
new CopyPlugin({
|
|
78
|
+
patterns: [
|
|
79
|
+
{
|
|
80
|
+
from:
|
|
81
|
+
'../../../externals/sam_l',
|
|
82
|
+
to: '${destPath.replace(/\\/g, '/')}/sam_l',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
from:
|
|
86
|
+
'../../../externals/sam_h',
|
|
87
|
+
to: '${destPath.replace(/\\/g, '/')}/sam_h',
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
}),
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
, other build systems might have a different way to do this.
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cornerstonejs/ai",
|
|
3
|
+
"version": "2.10.0",
|
|
4
|
+
"description": "AI and ML Interfaces for Cornerstone3D",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"module": "./dist/esm/index.js",
|
|
9
|
+
"types": "./dist/esm/index.d.ts",
|
|
10
|
+
"directories": {
|
|
11
|
+
"build": "dist"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./dist/esm/index.js",
|
|
16
|
+
"types": "./dist/esm/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "jest --testTimeout 60000",
|
|
24
|
+
"clean": "rimraf dist",
|
|
25
|
+
"build": "yarn run build:esm",
|
|
26
|
+
"build:esm": "tsc --project ./tsconfig.json",
|
|
27
|
+
"build:esm:watch": "tsc --project ./tsconfig.json --watch",
|
|
28
|
+
"dev": "tsc --project ./tsconfig.json --watch",
|
|
29
|
+
"build:all": "yarn run build:esm",
|
|
30
|
+
"build:update-api": "yarn run build:esm && api-extractor run --local",
|
|
31
|
+
"start": "tsc --project ./tsconfig.json --watch",
|
|
32
|
+
"format": "prettier --write 'src/**/*.js' 'test/**/*.js'",
|
|
33
|
+
"lint": "eslint --fix ."
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/dcmjs-org/dcmjs.git"
|
|
38
|
+
},
|
|
39
|
+
"author": "@cornerstonejs",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/cornerstonejs/cornerstone3D/issues"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/cornerstonejs/cornerstone3D/blob/main/packages/ai/README.md",
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@babel/runtime-corejs2": "^7.17.8",
|
|
47
|
+
"buffer": "^6.0.3",
|
|
48
|
+
"dcmjs": "^0.29.8",
|
|
49
|
+
"gl-matrix": "^3.4.3",
|
|
50
|
+
"lodash.clonedeep": "^4.5.0",
|
|
51
|
+
"ndarray": "^1.0.19",
|
|
52
|
+
"onnxruntime-common": "1.17.1",
|
|
53
|
+
"onnxruntime-web": "1.17.1"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@cornerstonejs/core": "^2.10.0",
|
|
57
|
+
"@cornerstonejs/tools": "^2.10.0"
|
|
58
|
+
},
|
|
59
|
+
"gitHead": "aab86e3f13a86bcd2d975a4cfbdf7eee7fa1627a"
|
|
60
|
+
}
|