cszn / DnCNN

Beyond a Gaussian Denoiser: Residual Learning of Deep CNN for Image Denoising (TIP, 2017)
https://cszn.github.io/
1.42k stars 534 forks source link

About image shape debug #98

Open darkkkcc opened 1 year ago

darkkkcc commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.