tensorflow / tensorflow/tflite-support

vision.ImageSegmenter fails when image array is F-continguous

Open
#894 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
441
Forks
146
PR merge metrics
No merged PRs in 30d

Description

When using numpy in python, the ordering of array elements in memory is handled under the hood and usually the user never has to worry about this. For instance, when I read an image file from disk parse it as a numpy array with image = np.asarray(Image.open('image.jpg')), it is loaded in C-contiguous format. If I decide to crop the image by slicing (crop = image[20:-20, 30:-3]) I will get an F-contiguous array as a result.

If I try to run segmentation inference using the vision.ImageSegmenter.segment() method with a C-contiguous array as input, it works fine. If the input image array is F-contiguous, the model happily returns garbage.

Versions:
numpy: 1.23.1
python 3.9.10
tflife-support: 0.4.2
tensorflow: 2.8.3

Suggested fix:
Add the following to the inference method:

    if not image_array.data.c_contiguous:
        image_array = np.ascontiguousarray(image_array)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the vision.ImageSegmenter.segment() entry point and reproduce the issue with C-contiguous and F-contiguous NumPy image arrays. Verify that segmentation results are correct for both layouts; the issue's suggested NumPy conversion describes the expected direction, but no file or test path is provided.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python, tensorflow
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.