jrsimuix commited on
Commit
ed22dc9
1 Parent(s): 8614e23

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +77 -3
README.md CHANGED
@@ -1,3 +1,77 @@
1
- ---
2
- license: cc
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc
3
+ ---
4
+
5
+ ## Install following python libs
6
+
7
+ ```
8
+ pip3 install tensorflow
9
+ pip3 install tensorflowjs
10
+ pip3 install tf2onnx
11
+ pip3 install onnxruntime
12
+ pip3 install pillow
13
+ pip3 install optimum[exporters]
14
+ ```
15
+ Change to compatible version of numpy for tensorflow
16
+ ```
17
+ pip3 uninstall numpy
18
+ pip3 install numpy==1.23.5
19
+ ```
20
+
21
+ ## Node Install
22
+ Download install project dependencies.
23
+ ```
24
+ npm install
25
+ ```
26
+
27
+ ### Summary of Commands:
28
+
29
+ - Run the Node training script to save the Layers Model.
30
+ - Convert tfjs_layers_model → tfjs_graph_model
31
+ - Convert graph model to onnx
32
+ - Validate onnx structure
33
+ - Test Model
34
+
35
+ # 1. Create Tensorflow model in node
36
+
37
+ This will loop through the training images taking base folder name as the label for the images to be associated against.
38
+ Once complete saved-model/model.json is created.
39
+
40
+ ```
41
+ node generate.js
42
+ ```
43
+
44
+ # 2. Convert Model
45
+
46
+ Convert from layers to graph model this is required to generate an onnx from tf2onnx
47
+
48
+ ```
49
+ tensorflowjs_converter --input_format=tfjs_layers_model \ --output_format=tfjs_graph_model \ ./saved-model/layers-model/model.json \ ./saved-model/graph-model
50
+ ```
51
+
52
+ # 3. Convert to ONNX Model
53
+
54
+ This will convert to a ONNX model to be used with transformers.js on web or nodejs.
55
+ ```
56
+ python3 -m tf2onnx.convert --tfjs ./saved-model/graph-model/model.json --output ./saved-model/model.onnx
57
+ ```
58
+
59
+ Unable to figure a way to use Optimum with tensorflow.js models atm..
60
+
61
+ # 4. Validate ONNX
62
+
63
+ Make sure the conversion worked and no issues
64
+ ```
65
+ python3 validate_onnx.py
66
+ ```
67
+
68
+ # 5. Test ONNX Model python
69
+
70
+ update the image path in the code to point to an image to confirm working as expected
71
+ - I tested against one of the trained image that should give 1.
72
+ ```
73
+ python3 test_image.py
74
+ ```
75
+ Inference outputs: [array([[0., 1.]], dtype=float32)]
76
+
77
+