Instructions to use BunkerMinecraft/NeuRecAI with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use BunkerMinecraft/NeuRecAI with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://BunkerMinecraft/NeuRecAI") - Notebooks
- Google Colab
- Kaggle
Update inference.py
Browse files- inference.py +19 -2
inference.py
CHANGED
|
@@ -5,8 +5,20 @@ import numpy as np
|
|
| 5 |
|
| 6 |
with open("config.json") as f:
|
| 7 |
cfg = json.load(f)
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
model.load_weights("model.weights.h5")
|
| 11 |
|
| 12 |
def predict(image: Image.Image):
|
|
@@ -14,4 +26,9 @@ def predict(image: Image.Image):
|
|
| 14 |
x = np.array(img) / 255.0
|
| 15 |
x = np.expand_dims(x, 0)
|
| 16 |
y = model.predict(x)
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
with open("config.json") as f:
|
| 7 |
cfg = json.load(f)
|
| 8 |
+
|
| 9 |
+
class_names = ['battery', 'glass', 'metal', 'organic', 'paper', 'plastic']
|
| 10 |
|
| 11 |
+
base_model = tf.keras.applications.EfficientNetB7(weights=None)
|
| 12 |
+
model = models.Sequential([
|
| 13 |
+
base_model,
|
| 14 |
+
layers.GlobalAveragePooling2D(),
|
| 15 |
+
layers.Dropout(dropout_rate),
|
| 16 |
+
layers.Dense(256, activation='relu', kernel_regularizer=kr),
|
| 17 |
+
layers.Dropout(dropout_rate),
|
| 18 |
+
layers.Dense(128, activation='relu', kernel_regularizer=kr),
|
| 19 |
+
layers.Dropout(dropout_rate),
|
| 20 |
+
layers.Dense(num_classes, activation='softmax')
|
| 21 |
+
])
|
| 22 |
model.load_weights("model.weights.h5")
|
| 23 |
|
| 24 |
def predict(image: Image.Image):
|
|
|
|
| 26 |
x = np.array(img) / 255.0
|
| 27 |
x = np.expand_dims(x, 0)
|
| 28 |
y = model.predict(x)
|
| 29 |
+
class_idx = int(np.argmax(y, axis=1)[0])
|
| 30 |
+
confidence = float(np.max(y))
|
| 31 |
+
return {
|
| 32 |
+
"class": class_names[class_idx],
|
| 33 |
+
"confidence": confidence
|
| 34 |
+
}
|