I got unknown tensorflow cpu errors for me

Can you please help me

its my code

import tensorflow as tf
import os
import tensorflow_hub as hub
import pyautogui

# Load the object detection model from TensorFlow Hub
module_handle = "https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1"
detector = hub.load(module_handle).signatures['default']

# Set the path to the folder with the screenshots
screenshots_folder = r'C:\Users\d\PycharmProjects\pythonProject4\screenshots'

# Get a list of all the files in the folder
screenshots = os.listdir(screenshots_folder)

for screenshot in screenshots:
    # Open the screenshot
    img = tf.io.read_file(os.path.join(screenshots_folder, screenshot))
    img = tf.image.decode_png(img, channels=3)

    # Use TensorFlow Hub to detect objects in the screenshot
    predictions = detector(img)

    # Draw squares around the detected objects
    if 'detection_boxes' in predictions:
        detection_boxes = predictions['detection_boxes']
        detection_scores = predictions['detection_scores']
        for i in range(len(detection_boxes)):
            if detection_scores[i] > 0.5:
                x, y, w, h = detection_boxes[i]
                pyautogui.drawRectangle(x, y, w, h, width=2, outline='red')
    else:
        print("No object detected in the image")

and i get errors

2023-01-14 10:04:20.119392: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-01-14 10:05:31.713546: W tensorflow/core/grappler/costs/op_level_cost_estimator.cc:690] Error in PredictCost() for the op: op: “CropAndResize” attr { key: “T” value { type: DT_FLOAT } } attr { key: “extrapolation_value” value { f: 0 } } attr { key: “method” value { s: “bilinear” } } inputs { dtype: DT_FLOAT shape { dim { size: -2484 } dim { size: -2485 } dim { size: -2486 } dim { size: 1088 } } } inputs { dtype: DT_FLOAT shape { dim { size: -105 } dim { size: 4 } } } inputs { dtype: DT_INT32 shape { dim { size: -105 } } } inputs { dtype: DT_INT32 shape { dim { size: 2 } } value { dtype: DT_INT32 tensor_shape { dim { size: 2 } } int_val: 17 } } device { type: “CPU” vendor: “GenuineIntel” model: “110” frequency: 3000 num_cores: 6 environment { key: “cpu_instruction_set” value: “SSE, SSE2” } environment { key: “eigen” value: “3.4.90” } l1_cache_size: 32768 l2_cache_size: 262144 l3_cache_size: 9437184 memory_size: 268435456 } outputs { dtype: DT_FLOAT shape { dim { size: -105 } dim { size: 17 } dim { size: 17 } dim { size: 1088 } } }
Traceback (most recent call last):
File “C:\Users\anton\PycharmProjects\pythonProject4\deleteme.py”, line 22, in
predictions = detector(img)
File “C:\Users\anton\PycharmProjects\discord-api\pythonProject4\lib\site-packages\tensorflow\python\eager\polymorphic_function\monomorphic_function.py”, line 1474, in call
return self._call_impl(args, kwargs)
File “C:\Users\anton\PycharmProjects\discord-api\pythonProject4\lib\site-packages\tensorflow\python\eager\wrap_function.py”, line 243, in _call_impl
return super(WrappedFunction, self)._call_impl(
File “C:\Users\anton\PycharmProjects\discord-api\pythonProject4\lib\site-packages\tensorflow\python\eager\polymorphic_function\monomorphic_function.py”, line 1492, in _call_impl
return self._call_with_flat_signature(args, kwargs, cancellation_manager)
File “C:\Users\anton\PycharmProjects\discord-api\pythonProject4\lib\site-packages\tensorflow\python\eager\polymorphic_function\monomorphic_function.py”, line 1541, in _call_with_flat_signature
return self._call_flat(args, self.captured_inputs, cancellation_manager)
File “C:\Users\anton\PycharmProjects\discord-api\pythonProject4\lib\site-packages\tensorflow\python\eager\polymorphic_function\monomorphic_function.py”, line 1745, in _call_flat
return self._build_call_outputs(self._inference_function.call(
File “C:\Users\anton\PycharmProjects\discord-api\pythonProject4\lib\site-packages\tensorflow\python\eager\polymorphic_function\monomorphic_function.py”, line 378, in call
outputs = execute.execute(
File “C:\Users\anton\PycharmProjects\discord-api\pythonProject4\lib\site-packages\tensorflow\python\eager\execute.py”, line 52, in quick_execute
tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.InvalidArgumentError: cannot compute __inference_pruned_173604 as input #0(zero-based) was expected to be a float tensor but is a uint8 tensor [Op:__inference_pruned_173604]

Process finished with exit code 1

Hi @respo, you are getting this error due to the datatype of your input. By default your keras model expects float32 but you are passing a uint8. You have to change the input to float32 before passing it to the model. Thank You.

1 Like

Try this: img = tf.cast(img, tf.float32)