Esempio n. 1
0
    ROI_img = ori_img[BeginY:, ally[0]:ally[1], :].copy()
    ROIShape = ROI_img.shape

    FullImage = np.zeros(imshape)
    FinalShape = FinalShape * 1
    pred_imgFinal = cv2.resize(FinalShape.astype(np.uint8), (ROIShape[1], ROIShape[0]))
    FullImage[BeginY:, ally[0]:ally[1]] = pred_imgFinal
    NucluesImage = MatchTemplate(FullImage)
    NucluesImage = NucluesImage[BeginY:, ally[0]:ally[1]]

    tmp_img = np.zeros(imshape)
    tmp_label = FullImage.copy()
    # with open('./logs/data/%s_side.pkl'%img_path,'w+') as f:
    #     data = [tmp_img, tmp_label, img_path, ally]
    #     pkl.dump(data, f)
    MSE_loss = MSE_pixel_loss(tmp_img, tmp_label, img_path, ally)
    print 'sideoutput:', img_path, MSE_loss
    MSE_loss_list.append(MSE_loss)

    if save_test_img:
        pred_img = cv2.resize(new_Image.astype(np.uint8), (ROI_img.shape[1], ROI_img.shape[0]))
        tmp_img = pred_img.copy()
        tmp_ROI_img = ROI_img.copy()
        pred_img[pred_img==3]=2
        pred_img[NucluesImage==1]=3
        ROI_img = crop_boundry(ROI_img, pred_img)
        alpha_img = ori_img.copy()
        alpha_img[BeginY:, ally[0]:ally[1]] = ROI_img

        ROI_img = cv2.addWeighted(alpha_img, 0.4, ori_img, 0.6, 0)
        ## imshow the truth
Esempio n. 2
0
                ## imshow the truth
                ROI_img = get_truth(ROI_img, img_path, ally, BeginY)
                if not os.path.exists(os.path.join(args.results, model_name)):
                    os.mkdir(os.path.join(args.results, model_name))
                save_name = os.path.join(args.results, model_name, img_path)
                cv2.imwrite(save_name, ROI_img)

            # predict the boundary
            FullImage = np.zeros(imshape)
            FinalShape = FinalShape * 1
            pred_imgFinal = cv2.resize(FinalShape.astype(np.uint8),
                                       (ROIShape[1], ROIShape[0]))
            FullImage[BeginY:, ally[0]:ally[1]] = pred_imgFinal
            # cv2.imwrite('./tmp_data/%s.png' % img_path.split('.')[0], FullImage)
            tmp_img = np.zeros(imshape)
            MSE_loss = MSE_pixel_loss(tmp_img, FullImage, img_path, ally)
            MSE_loss_list.append(MSE_loss)
        MSE_loss = np.mean(np.stack(MSE_loss_list), 0)
        if np.mean(MSE_loss) < mean_loss:
            torch.save(model.state_dict(),
                       './models/%s/best.pth' % (model_name))
            print 'success save the best model'
            mean_loss = np.mean(MSE_loss)
        end = time.time()
        # print('epoch: {:d} | lr: {:f}  | MSE_loss: {:s}'.format(epoch, args.lr, MSE_loss))
        print('epoch: {:d} | lr: {:f}  | time: {:.2f}| MSE_loss: {:s}'.format(
            epoch, args.lr, end - start, MSE_loss))
        with open('./logs/test_%s_log.txt' % (model_name), 'a+') as f:
            log_str = ('epoch: {:d} | lr: {:f}  | MSE_loss: {:s}'.format(
                epoch, args.lr, MSE_loss))
            f.writelines(log_str + '\n')