@ruvector/cnn 0.1.2 → 0.1.3
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/README.md +23 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/ruvnet/RuVector/main/assets/ruvector/packages/ruvector-cnn.svg" alt="@ruvector/cnn: CNN feature extraction for image embeddings — SIMD-optimized, pure Rust compiled to WASM." width="100%"></p>
|
|
2
|
+
|
|
1
3
|
# @ruvector/cnn
|
|
2
4
|
|
|
3
5
|
[](https://www.npmjs.com/package/@ruvector/cnn)
|
|
@@ -28,13 +30,25 @@ const numbers = embedder.extract(imagePixels, 224, 224);
|
|
|
28
30
|
const similarity = embedder.cosineSimilarity(numbers1, numbers2);
|
|
29
31
|
```
|
|
30
32
|
|
|
33
|
+
> **Known issues in 0.1.1** (the `index.js` wrapper; the underlying WASM works):
|
|
34
|
+
> - `new CnnEmbedder(...)` throws `null pointer passed to rust` — the wrapper
|
|
35
|
+
> reads the config after the WASM constructor has consumed it.
|
|
36
|
+
> - `SimdOps.relu`, `SimdOps.relu6`, `SimdOps.l2Normalize` and
|
|
37
|
+
> `LayerOps.batchNorm` leave the input unchanged — the WASM returns a new
|
|
38
|
+
> array and the wrapper discards it.
|
|
39
|
+
> - `LayerOps.globalAvgPool` returns an empty array — the wrapper passes
|
|
40
|
+
> `(input, channels, spatialSize)` but the WASM expects
|
|
41
|
+
> `(input, height, width, channels)`.
|
|
42
|
+
>
|
|
43
|
+
> `init()`, `InfoNCELoss`, `TripletLoss` and `SimdOps.dotProduct` work as documented.
|
|
44
|
+
|
|
31
45
|
## Why Use This?
|
|
32
46
|
|
|
33
47
|
| What You Get | Why It Matters |
|
|
34
48
|
|--------------|----------------|
|
|
35
49
|
| Runs in the browser | No server costs, instant results |
|
|
36
50
|
| ~5ms per image | Fast enough for real-time |
|
|
37
|
-
| ~
|
|
51
|
+
| ~80KB download (52KB WASM + JS glue) | Small enough for any website |
|
|
38
52
|
| No API calls | Works offline, no per-image fees |
|
|
39
53
|
| Training included | Teach it your own categories |
|
|
40
54
|
|
|
@@ -210,6 +224,7 @@ const b = new Float32Array([5, 6, 7, 8]);
|
|
|
210
224
|
const result = SimdOps.dotProduct(a, b); // 70
|
|
211
225
|
|
|
212
226
|
// ReLU: set negative values to 0
|
|
227
|
+
// (intended in-place; a no-op in 0.1.1, see Known issues)
|
|
213
228
|
const data = new Float32Array([-1, 0, 1, 7]);
|
|
214
229
|
SimdOps.relu(data); // [0, 0, 1, 7]
|
|
215
230
|
|
|
@@ -245,7 +260,7 @@ For best speed, use browsers with SIMD128 support:
|
|
|
245
260
|
## Troubleshooting
|
|
246
261
|
|
|
247
262
|
**"init() takes too long"**
|
|
248
|
-
- Normal: First call downloads ~
|
|
263
|
+
- Normal: First call downloads and compiles the ~52KB WASM file
|
|
249
264
|
- Fix: Call init() early, before user needs results
|
|
250
265
|
|
|
251
266
|
**"Images look wrong"**
|
|
@@ -263,6 +278,7 @@ For best speed, use browsers with SIMD128 support:
|
|
|
263
278
|
|
|
264
279
|
```typescript
|
|
265
280
|
new CnnEmbedder(options?: {
|
|
281
|
+
inputSize?: number; // Default: 224
|
|
266
282
|
embeddingDim?: number; // Default: 512
|
|
267
283
|
normalize?: boolean; // Default: true
|
|
268
284
|
})
|
|
@@ -290,12 +306,12 @@ new TripletLoss(margin?: number) // Default: 1.0
|
|
|
290
306
|
.margin: number
|
|
291
307
|
```
|
|
292
308
|
|
|
293
|
-
## Related
|
|
309
|
+
## Related packages
|
|
294
310
|
|
|
295
|
-
- [
|
|
296
|
-
- [`@ruvector/
|
|
297
|
-
- [
|
|
311
|
+
- [`@ruvector/attention`](https://www.npmjs.com/package/@ruvector/attention) — attention layers from the same RuVector ML toolkit.
|
|
312
|
+
- [`@ruvector/gnn`](https://www.npmjs.com/package/@ruvector/gnn) — graph neural network layers from the same toolkit.
|
|
313
|
+
- [`ruvector`](https://www.npmjs.com/package/ruvector) — umbrella package and CLI (`npx ruvector`); stores and searches the embeddings this package produces.
|
|
298
314
|
|
|
299
315
|
## License
|
|
300
316
|
|
|
301
|
-
MIT
|
|
317
|
+
MIT
|