0
$\begingroup$

I have a multi output segmentation task, the training process went well, but when Im trying to get the prediction I found difficulties to separate the two output into two different folders, in my dataset I have one image and two relating masks, I used this test generator:

def testGenerator(test_path= "data/membrane/test/image",num_image = 1584,target_size = (224,224),flag_multi_class = False,as_gray = False):
  for i in range(num_image):
    img = io.imread(os.path.join(test_path,"%d.jpg"%i),as_gray = as_gray)
    img = img / 255.
    img = trans.resize(img,target_size)
    img = np.reshape(img,img.shape) if (not flag_multi_class) else img
    img = np.reshape(img,(1,)+img.shape)
    yield img

and this is the code for model.test_generator:

testGene = testGenerator("data/membrane/test/image")
model = new_model()
model.load_weights("new_model.hdf5")
(conv11, convc11) = model.predict_generator(testGene,10,verbose=1)

saveResult(conv11,"data/membrane/test/results/road")
saveResult(convc11,"data/membrane/test/results/cl")

for visualization I used this :

def labelVisualize(num_class,color_dict,img):
    img = img[:,:,0] if len(img.shape) == 3 else img
    img_out = np.zeros(img.shape + (3,))
    for i in range(num_class):
    img_out[img == i,:] = color_dict[i]
    return img_out / 255

def saveResult(save_path,npyfile,flag_multi_class = False,num_class = 2):
    for i,item in enumerate(npyfile):
    img = labelVisualize(num_class,COLOR_DICT,item) if flag_multi_class else item[:,:,0]
    io.imsave(os.path.join(save_path,"%d_predict.tif"%(i)),skimage.img_as_ubyte(img))
$\endgroup$
0
$\begingroup$

solve it, I just did this change:

from:

saveResult(conv11,"data/membrane/test/results/road")
saveResult(convc11,"data/membrane/test/results/cl")

to :

saveResult("data/membrane/test/results/road", conv11)
saveResult("data/membrane/test/results/cl",convc11)

and Ive got each output saved into different folders

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.