Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yasersakkaf opened this issue Jul 23, 2020 · 2 comments

Comments

@yasersakkaf
Copy link

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 ================================================================
@yasersakkaf yasersakkaf changed the title ValueError: Could not load image at /home/yaser.sakkaf/custom_ocr/fsdl-text-recognizer-project/lab1/text_recognizer/tests/support/emnist/U.png: ValueError: Could not load image at /home/..../fsdl-text-recognizer-project/lab1/text_recognizer/tests/support/emnist/U.png: Jul 23, 2020
@SebStrug
Copy link

SebStrug commented Aug 22, 2020

I encountered the same error. The .png files in emnist/ looks like they are corrupted as they load in as None
i.e. it is the assertion that fails here

            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

I resaved three images from data/processed/eminst/byclass.h5 into the directory text_recognizer/tests/support/eminst/ and deleted the original ones and the test passed.

@szelenka
Copy link

The problem with this is that the image files are stored on Git LFS, and if you do a basic git clone without having LFS installed/configured, it'll simply download the reference text file to the Git LFS location.

A solution is to install Git LFS, and do a git lfs pull from the root directory you did a git clone from. Then it'll reach out to Git LFS and download the images as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants