pixel-decoder
pixel-decoder copied to clipboard
Problems with training.py
Hello,
I tried using pixel-decoder as you suggested in the readme file, however I am having problems with training my dataset. I use: train.train(batch_size=4, imgs_folder=imgs, masks_folder=masks, models_folder=models, model_id='resnet_unet', origin_shape_no=256, border_no=32) where imgs and masks are directories for label-maker data. However, after generating the first batch of results, I get the following ValueError: Cannot feed value of shape (4, 256, 256, 3, 1) for Tensor 'conv2d_22_target:0', which has shape '(?, ?, ?, ?)'.
From the Traceback, I believe this comes from the first instance of fit_generator, on lines 66-70. Specifically, the traceback points to line 70, the callback.
这个项目很好, 我很高兴!
哈哈,谢谢你的赞赏, @chloe-hampton。
The error comes from the labels. Label Maker creates 3 color channel labels for preview purpose, and you have to reshape the numpy array from (256, 256, 3) to (256, 256). I added utility script to convert it, see the script in this jupyter notebook I prepared for a conference.
In short, you can directly do:
from os import makedirs, path as op
from PIL import Image
import numpy as np
labels = np.load('labels.npz')
for label in labels.files:
new_label_dir = op.join(os.getcwd(), "new_labels")
if not op.isdir(new_label_dir):
makedirs(new_label_dir)
img = Image.fromarray(labels[label])
print('Writing {}'.format(label))
img.save('{}/{}.png'.format(new_label_dir, label))