import tensorflow.keras
from PIL import Image
import numpy as np
np.set_printoptions(suppress=True)
model = tensorflow.keras.models.load_model('keras_model.h5')
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
image = Image.open('skoda.jpg')
image = image.resize((224, 224))
image_array = np.asarray(image)
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
data[0] = normalized_image_array
prediction = model.predict(data)
print("Ford",prediction[0,0])
print("Fox",prediction[0,1])
print("Hundae",prediction[0,2])
print("Lexus",prediction[0,3])
print("Ferrari",prediction[0,4])
print("Chevrolet",prediction[0,5])
print("Nissan",prediction[0,6])
print("Skoda",prediction[0,7])
print(prediction)
Runtime
Ford 8.9526235e-05
Fox 0.00031412177
Hundae 2.5784022e-05
Lexus 1.4473101e-05
Ferrari 0.008922634
Chevrolet 3.905558e-05
Nissan 5.2737455e-06
Skoda 0.99058914
[[0.00008953 0.00031412 0.00002578 0.00001447 0.00892263 0.00003906
0.00000527 0.99058914]]
That's how it's printed It doesn't print out from the decimal point. How can I fix it? Is it possible?
python
Instead of answering with the example below.
In [1]: import numpy as np
In [2]: nums = np.array([0.00008953, 0.00031412, 0.00002578, 0.00001447, 0.00892263, 0.00003906, 0.00000527, 0.99058914])
In [3]: for i in nums: print(f"{i}")
8.953e-05
0.00031412
2.578e-05
1.447e-05
0.00892263
3.906e-05
5.27e-06
0.99058914
In [4]: for i in nums: print(f"{i:.8f}")
0.00008953
0.00031412
0.00002578
0.00001447
0.00892263
0.00003906
0.00000527
0.99058914
© 2024 OneMinuteCode. All rights reserved.