Closed AlexunderMicrocontrol closed 8 years ago
@AlexUnderMicrocontRoll could you provide your code (or a link to it), this way I can't figure it out.
code changes from data.py
`def create_train_data(): train_data_path = os.path.join(data_path, 'train') images = os.listdir(train_data_path) total = len(images) / 2
imgs = np.ndarray((total, 1, image_rows, image_cols), dtype=np.uint8)
imgs_mask = np.ndarray((total, 1, image_rows, image_cols), dtype=np.uint8)
i = 0
print('-'*30)
print('Creating training images...')
print('-'*30)
for image_name in images:
if 'mask' in image_name or '.DS_Store' in image_name:
continue
image_mask_name = image_name.split('.')[0] + '_mask.png'
img = cv2.imread(os.path.join(train_data_path, image_name), cv2.IMREAD_GRAYSCALE)
img_mask = cv2.imread(os.path.join(train_data_path, image_mask_name), cv2.IMREAD_GRAYSCALE)
img = np.array([img])
img_mask = np.array([img_mask])
imgs[i] = img
imgs_mask[i] = img_mask
if i % 100 == 0:
print('Done: {0}/{1} images'.format(i, total))
i += 1
print('Loading done.')
np.save('imgs_train.npy', imgs)
np.save('imgs_mask_train.npy', imgs_mask)
print('Saving to .npy files done.')`
`def create_test_data(): train_data_path = os.path.join(data_path, 'test') images = os.listdir(train_data_path) total = len(images)
imgs = np.ndarray((total, 1, image_rows, image_cols), dtype=np.uint8)
imgs_id = np.ndarray((total, ), dtype=np.int32)
i = 0
print('-'*30)
print('Creating test images...')
print('-'*30)
for image_name in images:
if 'mask' in image_name or '.DS_Store' in image_name:
continue
img_id = int(image_name.split('.')[0])
img = cv2.imread(os.path.join(train_data_path, image_name), cv2.IMREAD_GRAYSCALE)
img = np.array([img])
imgs[i] = img
imgs_id[i] = img_id
if i % 100 == 0:
print('Done: {0}/{1} images'.format(i, total))
i += 1
print('Loading done.')
np.save('imgs_test.npy', imgs)
np.save('imgs_id_test.npy', imgs_id)
print('Saving to .npy files done.')`
and inside your data.py i just changed the first lines:
img_rows = 351 img_cols = 638
images are from here i extract only the cars from the labeled images. Here is an example of my mask:
i hope it will possible to recognize cars with your model as start code :)
and here is the original image
The problem is in img_rows = 351 img_cols = 638
.
Since there are 4 2x2 pooling layers, you should make sure your input dimensions are divisible by 2^4=16. So, I guess you can try by resizing the images to 384x640.
Ok that works. THX
Hi Marko, I'am trying to use your code. My images are .png files. data.py runs without exceptions. but train.py fails in that line 51
up6 = merge([UpSampling2D(size=(2, 2))(conv5), conv4], mode='concat', concat_axis=1)
with that exception message:Exception: "concat" mode can only merge layers with matching output shapes except for the concat axis. Layer shapes: [(None, 512, 42, 78), (None, 256, 43, 79)]
I know the shapes doesn't match, but why? during competion your code runs well with original ultrasound images(.tiff). Could you help me please to customize your code that i can train your model on my own images?