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 +9 -9
inference.py
CHANGED
|
@@ -14,12 +14,12 @@ base_model = tf.keras.applications.EfficientNetB7(weights=None)
|
|
| 14 |
model = models.Sequential([
|
| 15 |
base_model,
|
| 16 |
layers.GlobalAveragePooling2D(),
|
| 17 |
-
layers.Dropout(
|
| 18 |
-
layers.Dense(256, activation='relu', kernel_regularizer=
|
| 19 |
-
layers.Dropout(
|
| 20 |
-
layers.Dense(128, activation='relu', kernel_regularizer=
|
| 21 |
-
layers.Dropout(
|
| 22 |
-
layers.Dense(
|
| 23 |
])
|
| 24 |
model.load_weights("model.weights.h5")
|
| 25 |
|
|
@@ -31,9 +31,9 @@ def preprocess(image: Image.Image):
|
|
| 31 |
|
| 32 |
def predict(image: Image.Image):
|
| 33 |
x = preprocess(image)
|
| 34 |
-
|
| 35 |
-
class_idx = int(np.argmax(
|
| 36 |
-
confidence = float(np.max(
|
| 37 |
return {
|
| 38 |
"class": class_names[class_idx],
|
| 39 |
"confidence": confidence
|
|
|
|
| 14 |
model = models.Sequential([
|
| 15 |
base_model,
|
| 16 |
layers.GlobalAveragePooling2D(),
|
| 17 |
+
layers.Dropout(0.3),
|
| 18 |
+
layers.Dense(256, activation='relu', kernel_regularizer=regularizers.l2(0.001)),
|
| 19 |
+
layers.Dropout(0.3),
|
| 20 |
+
layers.Dense(128, activation='relu', kernel_regularizer=regularizers.l2(0.001)),
|
| 21 |
+
layers.Dropout(0.3),
|
| 22 |
+
layers.Dense(6, activation='softmax')
|
| 23 |
])
|
| 24 |
model.load_weights("model.weights.h5")
|
| 25 |
|
|
|
|
| 31 |
|
| 32 |
def predict(image: Image.Image):
|
| 33 |
x = preprocess(image)
|
| 34 |
+
x = model.predict(x)
|
| 35 |
+
class_idx = int(np.argmax(x, axis=1)[0])
|
| 36 |
+
confidence = float(np.max(x))
|
| 37 |
return {
|
| 38 |
"class": class_names[class_idx],
|
| 39 |
"confidence": confidence
|