You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tensorflow.js gives the correct result but Tensorflow(keras_model.h5) gives the incorrect result.
I export the same training project, why this gives me different results.
I just change webcam to file using Tensorflow.js
Tensorflow.js
// run the webcam image through the image model
async function predict() {
// predict can take in an image, video or canvas html element
const image = document.getElementById("face-image");
if (image == null) {
alert("Please select image.");
return;
}
labelContainer.innerHTML = "";
const prediction = await model.predict(image, false);
for (let i = 0; i < maxPredictions; i++) {
const classPrediction =
prediction[i].className + ": " + prediction[i].probability.toFixed(2);
labelContainer.childNodes[i].innerHTML = classPrediction;
}
}
return: [[1.0 0]] (correct)
Tensorflow(keras_model.h5)
# Create the array of the right shape to feed into the keras model
# The 'length' or number of images you can put into the array is
# determined by the first position in the shape tuple, in this case 1.
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
# Replace this with the path to your image
image = Image.open(image_file_path)
# resize the image to a 224x224 with the same strategy as in TM2:
# resizing the image to be at least 224x224 and then cropping from the center
size = (224, 224)
image = ImageOps.fit(image, size, Image.ANTIALIAS)
# turn the image into a numpy array
image_array = np.asarray(image)
# display the resized image
image.show()
# Normalize the image
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
# Load the image into the array
data[0] = normalized_image_array
# run the inference
prediction = model.predict(data)
return: [[0.32318377 0.6768162]]
The text was updated successfully, but these errors were encountered:
I am trying to use for image filtering.
Tensorflow.js gives the correct result but Tensorflow(keras_model.h5) gives the incorrect result.
I export the same training project, why this gives me different results.
I just change webcam to file using Tensorflow.js
return: [[1.0 0]] (correct)
return: [[0.32318377 0.6768162]]
The text was updated successfully, but these errors were encountered: