Skip to content

ValueError: Could not load image at /home/..../fsdl-text-recognizer-project/lab1/text_recognizer/tests/support/emnist/U.png: #19

@yasersakkaf

Description

@yasersakkaf

In Lab_1 , when I try to run
tasks/test_functionality.sh
or
pytest -s text_recognizer/tests/test_character_predictor.py

I get the error mentioned in the issue title.
The entire error is as follows:

========================================================================= FAILURES ==========================================================================
___________________________________________________________ TestCharacterPredictor.test_filename ____________________________________________________________

self = <test_character_predictor.TestCharacterPredictor testMethod=test_filename>

    def test_filename(self):
        """Test that CharacterPredictor correctly predicts on a single image, for serveral test images."""
        predictor = CharacterPredictor()

        for filename in SUPPORT_DIRNAME.glob("*.png"):
>           pred, conf = predictor.predict(str(filename))

text_recognizer/tests/test_character_predictor.py:21:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
text_recognizer/character_predictor.py:20: in predict
    image = util.read_image(image_or_filename, grayscale=True)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

image_uri = '/home/yaser.sakkaf/custom_ocr/fsdl-text-recognizer-project/lab1/text_recognizer/tests/support/emnist/U.png', grayscale = True

    def read_image(image_uri: Union[Path, str], grayscale=False) -> np.array:
        """Read image_uri."""

        def read_image_from_filename(image_filename, imread_flag):
            return cv2.imread(str(image_filename), imread_flag)

        def read_image_from_url(image_url, imread_flag):
            url_response = urlopen(str(image_url))  # nosec
            img_array = np.array(bytearray(url_response.read()), dtype=np.uint8)
            return cv2.imdecode(img_array, imread_flag)

        imread_flag = cv2.IMREAD_GRAYSCALE if grayscale else cv2.IMREAD_COLOR
        local_file = os.path.exists(image_uri)
        try:
            img = None
            if local_file:
                img = read_image_from_filename(image_uri, imread_flag)
            else:
                img = read_image_from_url(image_uri, imread_flag)
            assert img is not None
        except Exception as e:
>           raise ValueError("Could not load image at {}: {}".format(image_uri, e))
E           ValueError: Could not load image at /home/yaser.sakkaf/custom_ocr/fsdl-text-recognizer-project/lab1/text_recognizer/tests/support/emnist/U.png:

text_recognizer/util.py:35: ValueError
===================================================================== warnings summary ======================================================================
/opt/anaconda3/envs/fsdl-text-recognizer/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py:15
  /opt/anaconda3/envs/fsdl-text-recognizer/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py:15: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp

-- Docs: https://docs.pytest.org/en/latest/warnings.html
================================================================== short test summary info ==================================================================
FAILED text_recognizer/tests/test_character_predictor.py::TestCharacterPredictor::test_filename - ValueError: Could not load image at /home/yaser.sakkaf/c...
=============================================================== 1 failed, 1 warning in 1.62s ================================================================

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions