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 +7 -3
inference.py
CHANGED
|
@@ -21,10 +21,14 @@ model = models.Sequential([
|
|
| 21 |
])
|
| 22 |
model.load_weights("model.weights.h5")
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
def predict(image: Image.Image):
|
| 25 |
-
|
| 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))
|
|
|
|
| 21 |
])
|
| 22 |
model.load_weights("model.weights.h5")
|
| 23 |
|
| 24 |
+
def preprocess(image: Image.Image):
|
| 25 |
+
image = image.resize((224, 224))
|
| 26 |
+
image = np.array(image) / 255.0
|
| 27 |
+
image = np.expand_dims(image, axis=0)
|
| 28 |
+
return image
|
| 29 |
+
|
| 30 |
def predict(image: Image.Image):
|
| 31 |
+
x = preprocess(image)
|
|
|
|
|
|
|
| 32 |
y = model.predict(x)
|
| 33 |
class_idx = int(np.argmax(y, axis=1)[0])
|
| 34 |
confidence = float(np.max(y))
|