ct_segnet/train_utils.py
def save_results(dg, model_results, segmenter):
    """Save some results on test images into a folder in the path to model repo
    """
    x_test, y_test = next(dg)
    y_pred = segmenter.predict(x_test)
    y_pred = np.round(y_pred)
    
    x_test, y_test, y_pred = x_test[...,0], y_test[...,0], y_pred[...,0]
    
    if not os.path.exists(os.path.join(model_results,"data_snaps")):
        os.makedirs(os.path.join(model_results,"data_snaps"))
    
    for ii in x_test.shape[0]:
            
            fig, ax = plt.subplots(1,3, figsize = (9,3))
            ax[0].axis('off')
            ax[0].imshow(x_test[ii])
            ax[1].axis('off')
            ax[1].imshow(y_test[ii])
            ax[2].axis('off')
            ax[2].imshow(y_pred[ii])
            
            #jac_acc = (np.sum(y_pred[ii]*y_test[ii]) + 1) / (np.sum(y_pred[ii]) + np.sum(y_test[ii]) - np.sum(y_pred[ii]*y_test[ii]) + 1)
            test_loss, jac_acc, acc_zeros, acc_ones = segmenter.evaluate(x = x_test[ii][np.newaxis,...,np.newaxis], y = y_test[ii][np.newaxis,...,np.newaxis], verbose = 0)
            
            fig.suptitle("IMG_MEAN: %.2f, JAC_ACC: %.2f, LOSS: %.2f"%(np.mean(x_test[ii]),jac_acc, test_loss))
            plt.savefig(os.path.join(model_results,"data_snaps",'snap_%05d.png'%ii))
            plt.close()

    return
Save some results on test images into a folder in the path to model repo
    
Save some results on test images into a folder in the path to model repo
Save some results on test images into a folder in the path to model repo
def save_results(dg, model_results, segmenter):
    x_test, y_test = next(dg)
    y_pred = segmenter.predict(x_test)
    y_pred = np.round(y_pred)
    x_test, y_test, y_pred = x_test[...,0], y_test[...,0], y_pred[...,0]
    if not os.path.exists(os.path.join(model_results,"data_snaps")):
        os.makedirs(os.path.join(model_results,"data_snaps"))
    for ii in x_test.shape[0]:
            fig, ax = plt.subplots(1,3, figsize = (9,3))
            ax[0].axis('off')
            ax[0].imshow(x_test[ii])
            ax[1].axis('off')
            ax[1].imshow(y_test[ii])
            ax[2].axis('off')
            ax[2].imshow(y_pred[ii])
            test_loss, jac_acc, acc_zeros, acc_ones = segmenter.evaluate(x = x_test[ii][np.newaxis,...,np.newaxis], y = y_test[ii][np.newaxis,...,np.newaxis], verbose = 0)
            fig.suptitle("IMG_MEAN: %.2f, JAC_ACC: %.2f, LOSS: %.2f"%(np.mean(x_test[ii]),jac_acc, test_loss))
            plt.savefig(os.path.join(model_results,"data_snaps",'snap_%05d.png'%ii))
            plt.close()
    return
def save_results ( dg , model_results , segmenter ) : x_test , y_test = next ( dg ) y_pred = segmenter . predict ( x_test ) y_pred = np . round ( y_pred ) x_test , y_test , y_pred = x_test [ ... , 0 ] , y_test [ ... , 0 ] , y_pred [ ... , 0 ] if not os . path . exists ( os . path . join ( model_results , "data_snaps" ) ) : os . makedirs ( os . path . join ( model_results , "data_snaps" ) ) for ii in x_test . shape [ 0 ] : fig , ax = plt . subplots ( 1 , 3 , figsize = ( 9 , 3 ) ) ax [ 0 ] . axis ( 'off' ) ax [ 0 ] . imshow ( x_test [ ii ] ) ax [ 1 ] . axis ( 'off' ) ax [ 1 ] . imshow ( y_test [ ii ] ) ax [ 2 ] . axis ( 'off' ) ax [ 2 ] . imshow ( y_pred [ ii ] ) test_loss , jac_acc , acc_zeros , acc_ones = segmenter . evaluate ( x = x_test [ ii ] [ np . newaxis , ... , np . newaxis ] , y = y_test [ ii ] [ np . newaxis , ... , np . newaxis ] , verbose = 0 ) fig . suptitle ( "IMG_MEAN: %.2f, JAC_ACC: %.2f, LOSS: %.2f" % ( np . mean ( x_test [ ii ] ) , jac_acc , test_loss ) ) plt . savefig ( os . path . join ( model_results , "data_snaps" , 'snap_%05d.png' % ii ) ) plt . close ( ) return
Save some results on test images into a folder in the path to model repo
Save some results on test images into a folder in the path to model repo
"""Save some results on test images into a folder in the path to model repo
    """ #jac_acc = (np.sum(y_pred[ii]*y_test[ii]) + 1) / (np.sum(y_pred[ii]) + np.sum(y_test[ii]) - np.sum(y_pred[ii]*y_test[ii]) + 1)
dg
model_results
segmenter