Closed kapilb7 closed 3 years ago
This is most likely a problem with your file path. cv2.imread()
returns None
when the file you're trying to read does not exist, and the AttributeError
you're seeing is the result of None
not having a shape
attribute.
You can print the path here and then check if there is a file at that path.
Hi, I tried printing the img variable to see what it shows, it does display many matrices, but at the end shows a 'none', maybe that's the reason. But why is this happening...?
OUTPUT: ... [19 19 19] [18 18 18] [18 18 18]]
[[13 13 13]
[13 13 13]
[13 13 13]
...
[19 19 19]
[19 19 19]
[17 17 17]]]
None
Traceback (most recent call last):
File "eval.py", line 66, in
Try printing the filenames rather than the output from cv2.imread
. From what I can tell, there seems to one or more missing image files in your dataset, and so printing the filenames will help you identify which files they are. Try modifying the process_image_file
function with this snippet:
def process_image_file(filepath, top_percent, size):
img = cv2.imread(filepath)
# Print filepath if imread fails
if img is None:
print(os.path.exists(filepath), filepath)
img = crop_top(img, percent=top_percent)
img = central_crop(img)
img = cv2.resize(img, (size, size))
return img
I suspect this will print False, <filepath>
in your case, just before the AttributeError
is raised.
I'm trying to run the eval.py program on the pre-trained COVIDNet-CXR-Large dataset, I'm getting the following error:
WARNING:tensorflow:From /Users/kapil/.local/lib/python3.8/site-packages/tensorflow/python/compat/v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term 2021-03-01 22:03:55.225002: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set 2021-03-01 22:03:55.225302: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2021-03-01 22:03:59.754462: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:196] None of the MLIR optimization passes are enabled (registered 0 passes) Traceback (most recent call last): File "eval.py", line 80, in
eval(sess, graph, testfile, args['testfolder'], args['in_tensorname'], args['out_tensorname'], args['input_size'])
File "eval.py", line 24, in eval
x = process_image_file(os.path.join(testfolder, line[1]), 0.08, input_size)
File "/Users/kapil/Documents/COVIDNet-CXR-Large/data.py", line 22, in process_image_file
img = crop_top(img, percent=top_percent)
File "/Users/kapil/Documents/COVIDNet-CXR-Large/data.py", line 11, in crop_top
offset = int(img.shape[0] * percent)
AttributeError: 'NoneType' object has no attribute 'shape'