papousek commited on
Commit
1232ce7
·
verified ·
1 Parent(s): 5c0ccbd

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +35 -1
README.md CHANGED
@@ -7,10 +7,12 @@ tags:
7
 
8
  # Kindwise Crossroad Model
9
 
10
- ## The model use it
11
 
12
  Here is how to use this model to classify an image into one of the basic classes:
13
 
 
 
14
  ```python
15
  from huggingface_hub import hf_hub_download
16
  import cv2
@@ -64,3 +66,35 @@ Output:
64
  insect: 0.1%
65
  mushroom: 0.0%
66
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # Kindwise Crossroad Model
9
 
10
+ ## How to use
11
 
12
  Here is how to use this model to classify an image into one of the basic classes:
13
 
14
+ ### PyTorch
15
+
16
  ```python
17
  from huggingface_hub import hf_hub_download
18
  import cv2
 
66
  insect: 0.1%
67
  mushroom: 0.0%
68
  ```
69
+
70
+ ###
71
+
72
+ ### TensorFlow Lite
73
+
74
+ ```python
75
+ from huggingface_hub import hf_hub_download
76
+ import numpy as np
77
+ import tensorflow as tf
78
+
79
+ MODEL_PATH = hf_hub_download('kindwise/crossroad.tiny', 'model.tflite') # or model.optimized.tflite
80
+
81
+ INTERPRETER = tf.lite.Interpreter(model_path=MODEL_PATH)
82
+ INTERPRETER.allocate_tensors()
83
+
84
+ image_array_resized = ... # see the previous example
85
+ tf_input = np.expand_dims( # add batch dimension
86
+ (image_array_resized / 255).astype(np.float32), # image values in [0..1]
87
+ 0,
88
+ )
89
+ input_details = INTERPRETER.get_input_details()
90
+ output_details = INTERPRETER.get_output_details()
91
+ INTERPRETER.set_tensor(
92
+ input_details[0]['index'],
93
+ tf_input,
94
+ )
95
+ INTERPRETER.invoke()
96
+ logits = INTERPRETER.get_tensor(output_details[0]['index'])[0]
97
+ prediction = tf.nn.sigmoid(logits).numpy()
98
+ for i in (-prediction).argsort():
99
+ print(f'{classes[i]:>10}: {100 * prediction[i]:.1f}%')
100
+ ```