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

About image shape debug #98

Open
darkkkcc opened this issue May 18, 2023 · 2 comments
Open

About image shape debug #98

darkkkcc opened this issue May 18, 2023 · 2 comments

Comments

@darkkkcc
Copy link

I used my own dataset with an image size of 1536 * 2048, but an error was reported as follows: (ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (12, 88185) + inhomogeneous part.) How to debug? Thanks!!!

@dinavod12
Copy link

def datagenerator(data_dir='data/Train400', batch_size=128, verbose=False):
file_list = glob.glob(data_dir + '/*.png') # get name list of all .png files

data = []

for i, file_name in enumerate(file_list):
    patches = gen_patches(file_name)
    data.extend(patches)
    
    if verbose:
        print(f"{i+1}/{len(file_list)} is done ^_^")

# Convert the list of patches to a NumPy array
data = np.array(data, dtype='uint8')

# Calculate how many patches to discard for batch compatibility
discard_n = len(data) - len(data) // batch_size * batch_size
data = data[:-discard_n]

# Reshape data if patches have a consistent shape
# Adjust this reshape based on your actual patch shapes
data = data.reshape((-1, patch_size, patch_size, 1))

print('^_^-training data finished-^_^')
return data

I think now it will run okay..

@dinavod12
Copy link

Batch Size and discard_n: The discard_n value is calculated to remove any remaining data points that don't fit into full batches. However, it seems like you're using a variable batch_size that is not defined within this function. Make sure you pass the correct batch size to the function or define it within the function.

Data Shape: You reshape the data array at the end of the function using data.reshape((data.shape[0]*data.shape[1],data.shape[2],data.shape[3],1)). This assumes that the patches generated for each image are of the same shape. If your images have varying shapes after patch extraction, this reshape operation might not work as intended. You'll need to handle this based on the specific shapes of the patches you've generated.

Return Value: The function currently returns the variable data, which is an array containing all the generated patches. If this is your intended behavior, then the function is fine. However, if you want to return patches for each image separately, you might need to modify the structure of your returned data.

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