预测后如何生成准确的蒙版

时间:2020-09-10 19:05:04

标签: python opencv3.0

我正在使用深度学习方法来进行细分任务,经过训练后,我想对测试图像进​​行预测,因此我首先加载模型和图像,然后将生成的蒙版保存到文件夹中 enter image description here ,我使用了这段代码

model = load_model('..../accuracy.h5')#loading the model
TEST_PATH = ''#path to my test images
PRED_PATH = ''#path to where I want to save my generated masks 
#this block is used to read my test images and save them into X
test_ids  = os.listdir(TEST_PATH)
X = np.zeros((len(test_ids), IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS), dtype=np.uint8)
ctr=0
for n, id_ in tqdm(enumerate(test_ids), total=len(test_ids)):
    path = TEST_PATH + id_
    image_file = os.listdir(path + '/images/')
    X[ctr]  = imread(path+'/images/'+image_file[0])[:,:,:IMG_CHANNELS]
    ctr=ctr+1
 
preds_test = model.predict(X, verbose=1)#predictions on my images
#this block is used to save the generated mask intoa folder
ctr=0
for i in range(len(test_ids)):
    file_name=test_ids[i]+'pred.png'
    img=preds_test[ctr]
    imsave(PRED_PATH+file_name,img)
    ctr= ctr+1

这是生成的掩码的一个示例!

口罩的质量不好,我不知道我是否在预测过程中缺少任何东西!谁能帮我!

0 个答案:

没有答案