Skip to content

Bug function: reconstruct_from_patches_2d #10910

Closed
jiadongdan/scikit-learn
#1

Description

@jiadongdan

Description

Function reconstruct_from_patches_2d is getting the right answer!!!

Steps/Code to Reproduce

Code:

from time import time
import numpy as np
from sklearn.feature_extraction.image import extract_patches_2d
from sklearn.feature_extraction.image import reconstruct_from_patches_2d

img = np.ones((128, 256))

height, width = img.shape


# Extract all reference patches from the left half of the image
print('Extracting reference patches...')
t0 = time()
patch_size = (128, 128)
data = extract_patches_2d(img, patch_size)
#data = data.reshape(data.shape[0], -1)
#intercept = np.mean(data, axis=0)
#data -= intercept
print('done in %.2fs.' % (time() - t0))

b = reconstruct_from_patches_2d(data, img.shape)

Actual Results

b should be all ones!!!, The result is NOT!!!

Versions

Windows-10-10.0.16299-SP0
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]
NumPy 1.14.2
SciPy 1.0.1
Scikit-Learn 0.19.1

Activity

  1. lesteve commented on Apr 3, 2018

    @lesteve
    Member

    I can reproduce it seems like a bug indeed. Quickly trying out different values, it only seems to happen one of the patch size value is equal to one of the img.shape values. For example patch_size = (64, 128) works fine but not patch_size = (128, 128).

    Pull request more than welcome!

  2. jiadongdan commented on Apr 3, 2018

    @jiadongdan
    Author

    Hi, I also tried patch size (128, 128) with image shape (130 , 256), I cannot get expected result.

  3. added a commit that references this issue on Apr 4, 2018
  4. jiadongdan commented on Apr 4, 2018

    @jiadongdan
    Author

    Hi @lesteve. I figured out this problem... I made a few test on my machine. The basic idea is create a overlap count map, which is a combination of many min functions (actually it is combination of some piece-wise functions). The reasoning behind should be right, but I am not should there will be some plus one and minus one index issue. I tested some cases, it should work fine.

  5. jiadongdan commented on Apr 4, 2018

    @jiadongdan
    Author

    Hi @lesteve , I think now this function can work now, please kindly check...

  6. lesteve commented on Apr 4, 2018

    @lesteve
    Member

    Can you open a PR on the scikit-learn/scikit-learn repo? Unless I missed something you open a PR against your fork.

    You will need to add a non-regression test, have a look at our contribution guidelines.

  7. jiadongdan commented on Apr 4, 2018

    @jiadongdan
    Author

    I am a bit confused, I don't know which branches I should put this into...

  8. qinhanmin2014 commented on Apr 4, 2018

    @qinhanmin2014
    Member

    @GeekMe93 You need to fork the repo, create a branch to hold your work, and submit a PR to the master branch (Please refer to the contributing guide or Google for more details).

  9. cmarmo commented on Nov 23, 2020

    @cmarmo
    Contributor

    Hi @jiadong93 this bug is still in master. Are you still interested in fixing this? If yes, you can open a pull request from your branch to scikit-learn master branch. It would be even better if you synchronise with scikit-learn master branch before.

  10. jiadongdan commented on Feb 10, 2021

    @jiadongdan
    Author

    Hi, @cmarmo , sorry for very late reply. Is the issue solved for latest version of sklearn? If not, I am glad to help.

  11. cmarmo commented on Feb 10, 2021

    @cmarmo
    Contributor

    Hi @jiadong93 , the bug is still there. Would you be able to open a pull request from your branch to scikit-learn main branch? It would be even better if you synchronise with scikit-learn main branch before.

  12. added a commit that references this issue on Mar 26, 2026
    ff1c4bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions