StandardCAS-NSTID
commited on
Commit
•
4914bfe
1
Parent(s):
d42b500
Create Estallie_Interpretor.py
Browse files- Estallie_Interpretor.py +27 -0
Estallie_Interpretor.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
from tensorflow.keras.preprocessing import image
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
# Load the model
|
6 |
+
model = tf.keras.models.load_model('nsfw_classifier.h5')
|
7 |
+
|
8 |
+
# Load an image file to test, resizing it to 150x150 pixels (as required by this model)
|
9 |
+
img = image.load_img('', target_size=(512, 512))
|
10 |
+
|
11 |
+
# Convert the image to a numpy array
|
12 |
+
img_array = image.img_to_array(img)
|
13 |
+
|
14 |
+
# Add a fourth dimension to the image (since Keras expects a list of images, not a single image)
|
15 |
+
img_array = np.expand_dims(img_array, axis=0)/
|
16 |
+
|
17 |
+
# Normalize the image
|
18 |
+
img_array /= 255.
|
19 |
+
|
20 |
+
# Use the model to predict the image's class
|
21 |
+
pred = model.predict(img_array)
|
22 |
+
|
23 |
+
# The model returns a probability between 0 and 1
|
24 |
+
# You can convert this to the class label like this:
|
25 |
+
label = 'NSFW' if pred[0][0] > 0.5 else 'SFW'
|
26 |
+
print(pred[0][0])
|
27 |
+
print("The image is classified as:", label)
|