OneclickAI commited on
Commit
0ce2adf
·
verified ·
1 Parent(s): e2121f9
Files changed (1) hide show
  1. test.py +0 -33
test.py DELETED
@@ -1,33 +0,0 @@
1
- from huggingface_hub import hf_hub_download
2
- import tensorflow as tf
3
- from tensorflow import keras
4
-
5
- # Replace 'your-username/your-model-name' with your actual Hugging Face model repository ID.
6
- repo_id = "your-username/your-model-name"
7
- # Replace 'my_keras_model.keras' with the name of the file you uploaded.
8
- filename = "my_keras_model.keras"
9
-
10
- # Download the model file from the Hugging Face Hub.
11
- model_path = hf_hub_download(repo_id=repo_id, filename=filename)
12
-
13
- # Load the model using Keras's built-in function.
14
- # The 'safe_mode=False' argument is often necessary when loading models saved from older TensorFlow versions
15
- # or if the model contains custom layers.
16
- model = keras.models.load_model(model_path, safe_mode=False)
17
-
18
- # Now you can use the loaded model for inference.
19
- # Example: Load a single MNIST test image and make a prediction.
20
- (x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
21
- x_test = x_test.astype("float32") / 255.0
22
- x_test = tf.expand_dims(x_test, -1)
23
- image_to_predict = x_test[0:1]
24
-
25
- # Get the model's prediction.
26
- predictions = model.predict(image_to_predict)
27
-
28
- # Print the predicted class (the one with the highest probability).
29
- predicted_class = tf.argmax(predictions[0]).numpy()
30
- print(f"Predicted class: {predicted_class}")
31
-
32
- # Display the model summary to confirm it's loaded correctly.
33
- model.summary()