Hi there I'm quite new to this sort of stuff,
I'm at the final stages of completing my facial verification software and everything has run smoothly right up to the last section.
I've had an error.
It says that the error comes from the following and produces the following:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-148-2d15a2a2f252> in <module>
11 cv2.imwrite(os.path.join('application_data', 'input_image', 'input_image.jpg'), frame)
12 # Run verification
---> 13 results, verified = verify(model, 0.5, 0.5)
14 print(verified)
15
<ipython-input-147-a92e41905a3e> in verify(model, detection_threshold, verification_threshold)
4 for image in os.listdir(os.path.join('application_data', 'verification_images')):
5 input_img = preprocess(os.path.join('application_data', 'input_image', 'input_image.jpg'))
----> 6 validation_img = preprocess(os.path.join('application_data', 'verification_images', image))
7
8 # Make Predictions
<ipython-input-146-c90c40e2cf87> in preprocess(file_path)
4 byte_img = tf.io.read_file(file_path)
5 # Load in the image
----> 6 img = tf.io.decode_jpeg(byte_img)
7
8 # Preprocessing steps - resizing the image to be 100x100x3
~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/ops/gen_image_ops.py in decode_jpeg(contents, channels, ratio, fancy_upscaling, try_recover_truncated, acceptable_fraction, dct_method, name)
1166 pass
1167 try:
-> 1168 return decode_jpeg_eager_fallback(
1169 contents, channels=channels, ratio=ratio,
1170 fancy_upscaling=fancy_upscaling,
~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/ops/gen_image_ops.py in decode_jpeg_eager_fallback(contents, channels, ratio, fancy_upscaling, try_recover_truncated, acceptable_fraction, dct_method, name, ctx)
1240 fancy_upscaling, "try_recover_truncated", try_recover_truncated,
1241 "acceptable_fraction", acceptable_fraction, "dct_method", dct_method)
-> 1242 _result = _execute.execute(b"DecodeJpeg", 1, inputs=_inputs_flat,
1243 attrs=_attrs, ctx=ctx, name=name)
1244 if _execute.must_record_gradient():
~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
57 try:
58 ctx.ensure_initialized()
---> 59 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
60 inputs, attrs, num_outputs)
61 except core._NotOkStatusException as e:
InvalidArgumentError: Unknown image file format. One of JPEG, PNG, GIF, BMP required. [Op:DecodeJpeg]
However, I have checked all the images involved and they are all jpegs/jpg. I don't understand where I have gone wrong. Below is the function for verifying the images:
def verify(model, detection_threshold, verification_threshold):
# Build results array
results = []
for image in os.listdir(os.path.join('application_data', 'verification_images')):
input_img = preprocess(os.path.join('application_data', 'input_image', 'input_image.jpg'))
validation_img = preprocess(os.path.join('application_data', 'verification_images', image))
# Make Predictions
result = model.predict(list(np.expand_dims([input_img, validation_img], axis=1)))
results.append(result)
# Detection Threshold: Metric above which a prediciton is considered positive
detection = np.sum(np.array(results) > detection_threshold)
# Verification Threshold: Proportion of positive predictions / total positive samples
verification = detection / len(os.listdir(os.path.join('application_data', 'verification_images')))
verified = verification > verification_threshold
return results, verified
And this is the opencv code that provides me with the errors:
capture = cv2.VideoCapture(0)
while capture.isOpened():
ret, frame = capture.read()
frame = frame[200:200+250,500:500+250, :]
cv2.imshow('Verification', frame)
# Verification trigger
if cv2.waitKey(10) & 0xFF == ord('v'):
# Save input image to application_data/input_image folder
cv2.imwrite(os.path.join('application_data', 'input_image', 'input_image.jpg'), frame)
# Run verification
results, verified = verify(model, 0.5, 0.5)
print(verified)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
capture.release()
cv2.destroyAllWindows()