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

python run error with attached file "IndexError" #1

Open
ade585 opened this issue Mar 21, 2024 · 2 comments
Open

python run error with attached file "IndexError" #1

ade585 opened this issue Mar 21, 2024 · 2 comments

Comments

@ade585
Copy link

ade585 commented Mar 21, 2024

with files attached below I get a python error when launching --data_dir data/mytest

index error detected on def construct_A_matrix(self):
line A[self.inner_pos, n2_pos] = 1

can you check ?

mask
source
target

@ade585 ade585 changed the title some error with attached python error with attached Mar 21, 2024
@ade585 ade585 changed the title python error with attached python run error with attached file "IndexError" Mar 21, 2024
@YcZhangSing
Copy link

I meet the same err. It is raised from 'construct_A_matrix()' and index out of bounds. Could you please tell me how do you fixed it ? Thank you very much!

@YcZhangSing
Copy link

Well, I just simply add a index check :
`
def construct_A_matrix(self):

    n1_pos = np.searchsorted(self.mask_ids, self.inner_ids - 1)
    n2_pos = np.searchsorted(self.mask_ids, self.inner_ids + 1)
    n3_pos = np.searchsorted(self.mask_ids, self.inner_ids - self.img_w)
    n4_pos = np.searchsorted(self.mask_ids, self.inner_ids + self.img_w)


    # index check
    max_index = len(self.mask_ids) - 1
    n1_pos = np.clip(n1_pos, 0, max_index)
    n2_pos = np.clip(n2_pos, 0, max_index)
    n3_pos = np.clip(n3_pos, 0, max_index)
    n4_pos = np.clip(n4_pos, 0, max_index)
    ###### 
   


    #row_ids = np.concatenate([self.inner_pos, self.inner_pos, self.inner_pos, self.inner_pos, self.inner_pos, self.boundary_pos])
    #col_ids = np.concatenate([n1_pos, n2_pos, n3_pos, n4_pos, self.inner_pos, self.boundary_pos])
    #data = [1] * len(self.inner_pos) * 4 + [-4] * len(self.inner_pos) + [1] * len(self.boundary_pos)

    #A = scipy.sparse.csr_matrix((data, (row_ids, col_ids)), shape=(len(self.mask_ids), len(self.mask_ids)))

    A = scipy.sparse.lil_matrix((len(self.mask_ids), len(self.mask_ids)))
    A[self.inner_pos, n1_pos] = 1
    A[self.inner_pos, n2_pos] = 1
    A[self.inner_pos, n3_pos] = 1
    A[self.inner_pos, n4_pos] = 1
    A[self.inner_pos, self.inner_pos] = -4 
    A[self.boundary_pos, self.boundary_pos] = 1
    A = A.tocsr()
    
    return A

`
It seemed solved this problem. You can try it.

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

2 participants