コード例 #1
0
def test(test_loader, model, data_dir, save_dir, iteration):
    model.eval()

    itedir_out = os.path.join(save_dir, 'testResults', str(iteration))
    if not os.path.exists(os.path.join(save_dir, 'testResults')):
        os.mkdir(os.path.join(save_dir, 'testResults'))
    if not os.path.exists(itedir_out):
        os.mkdir(itedir_out)

    model = model.cuda()

    print('def test')

    for step, (images, enhance_params, fileName) in enumerate(test_loader):

        images = images.cuda()

        inputs = Variable(images, volatile=True)
        outputs = model(inputs)

        normalized_params = (outputs.data).cpu().numpy()
        denormalized_params = denormalize(normalized_params)
        #save descaled params, enhanced photos

        param_to_photoEnhance2test.param_to_photoEnhance(
            denormalized_params.flatten(), fileName[0], data_dir, itedir_out,
            'test')
コード例 #2
0
    patches = all_patches(256, *dims_desired)
    log.info(f"patches leng is {len(patches)} and predict is {len(prediction)}")
    for i in range(len(patches)): 
        output[patches[i]]=prediction[i]
    return output


ML_FULL_ARRAY = rebuild(prediction, dims_desired) #y

TRUTH_FULL_ARRAY = rebuild(truth, dims_desired) #x


#%%
#renormalize data ( raw and ML outputs)

yy = normalize.denormalize(whichtruth, ML_FULL_ARRAY)
xx = normalize.denormalize(whichtruth, TRUTH_FULL_ARRAY)

log.info(f'saving full images')
np.savez(spath + 'fullsize.npz', truth = xx, prediction = yy)


print( 'DNB raw truth max is', np.nanmax(xx))
print( 'DNB raw truth min is', np.nanmin (xx))
print( 'ML raw rad max is', np.max(yy))
print( 'ML raw rad min is', np.min(yy))

#%%

#ERF applications on ML and truth values for image translation
log.info(f'starting the ERF processes')
コード例 #3
0
def process_channel(Ycol, MLRcol, c, figdir, nick, metdict, shape, denormed):
    R2 = metrics.r2_score(Ycol, MLRcol)
    RMSE = metrics.mean_squared_error(Ycol, MLRcol, squared=False)
    MAE = metrics.mean_absolute_error(Ycol, MLRcol)
    metdict[c] = {}
    metdict[c][
        "regressions"] = f'R2 = {R2:.4f}, RMSE = {RMSE:.4f}, MAE = {MAE:.4f}'
    log.info(f'{c} y variance explained by all predictors fit = ' +
             str(np.round(R2, 5)))
    log.info(f'{c} RMSE = ' + str(np.round(RMSE, 5)))
    log.info(f'{c} MAE = ' + str(np.round(MAE, 5)))
    plotdata(Ycol, MLRcol, c, figdir, nick)

    MLR_pred = normalize.denormalize(c, MLRcol)
    truth = normalize.denormalize(c, Ycol)
    MLR_pred_r = MLR_pred.reshape(shape)
    truth_r = truth.reshape(shape)

    denormed[c] = np.stack((MLR_pred_r, truth_r), axis=-1)

    #boxplots
    log.info(' making boxplots')
    plt.boxplot([truth.flatten(), MLR_pred.flatten()],
                labels=["truth", "MLR"],
                sym='')
    plt.title(f'Data Point Distribution for {c}')
    plt.savefig(figdir / f"{nick}_{c}_boxplot.png")
    plt.close()

    plt.boxplot(truth.flatten(), sym='')
    plt.title(f'Data Point Distribution for {c} truth')
    plt.savefig(figdir / f"{nick}_{c}_boxplot_truth.png")
    plt.close()

    plt.boxplot(MLR_pred.flatten(), sym='')
    plt.title(f'Data Point Distribution for {c} MLR')
    plt.savefig(figdir / f"{nick}_{c}_boxplot_MLR.png")
    plt.close()

    coledir = figdir / "RAWimages"
    coledir.mkdir(exist_ok=True, parents=True)
    should_invert = 'log' in c
    for i in range(shape[0]):
        #COLE PLOTTING
        show_byte_img(scale(truth_r[i], 5, invert=should_invert),
                      name=coledir / f"{nick}_{c}_COLE_truth_{i}.png")
        show_byte_img(scale(MLR_pred_r[i], 5, invert=should_invert),
                      name=coledir / f"{nick}_{c}_COLE_MLR_truth_{i}.png")

    truth_min, truth_max = np.nanmin(truth), np.nanmax(truth)
    MLR_min, MLR_max = np.nanmin(MLR_pred), np.nanmax(MLR_pred)
    metdict[c][
        "denorm_raw"] = f'truth min/max = {truth_min:.4f}/{truth_max:.4f}, MLR_truth min/max = {MLR_min:.4f}/{MLR_max:.4f}'
    plotdata(MLR_pred, truth, c, figdir, nick + "denorm")

    #ERF applications on ML and truth values for image translation
    log.info(f'starting the ERF processes')
    ERFimage_truth, ERFimage_ML = ERF(truth,
                                      "truth"), ERF(MLR_pred, "MLR_pred")

    # plotting image pair
    x = ERFimage_truth.reshape(shape)  #[:2000]
    y = ERFimage_ML.reshape(shape)  #[:2000]

    denormed[f'{c}_BVI'] = np.stack((y, x), axis=-1)

    imagedir = figdir / "ERFimages"
    imagedir.mkdir(exist_ok=True, parents=True)

    # makes ERF
    for i in range(shape[0]):
        log.info(f'processing {i} image plotting')
        #ERF PLOTTING
        img = x[i]
        imgplot = plt.imshow(img, cmap='gray')  #, vmin=2000, vmax=5000)
        plt.grid(False)
        plt.title('ERF imagery truth')
        plt.colorbar()
        plt.savefig(imagedir / f"{nick}_{c}_ERFtruth_{i}.png")
        #plt.show()
        plt.close()

        img2 = y[i]
        imgplot = plt.imshow(img2, cmap='gray')  #,vmin=2000, vmax=5000)
        plt.grid(False)
        plt.title("ERF imagery ML")
        plt.colorbar()
        plt.savefig(imagedir / f"{nick}_{c}_ERF_MLR_truth_{i}.png")
        #plt.show()
        plt.close()
コード例 #4
0
           "my_csi50_metric": my_csi50_metric,\
           "my_bias20_metric": my_bias20_metric,\
           "my_bias35_metric": my_bias35_metric,\
          "my_bias50_metric": my_bias50_metric})
# "model_file"

#whichtruth = data['y_channel'][0]
#TODO - with new array adjust this
whichtruth = 'DNB_full_moon_norm'
truth = data['Ydata_train']
prediction = model.predict(data['Xdata_train'])

#%%
#renormalize data ( raw and ML outputs)

xx = normalize.denormalize(whichtruth, truth)
yy = normalize.denormalize(whichtruth, prediction)

print('DNB raw truth max is', np.nanmax(yy))
print('DNB raw truth min is', np.nanmin(yy))
print('ML raw rad max is', np.max(xx))
print('ML raw rad min is', np.min(xx))

##
#calculate RMSE
from sklearn.metrics import mean_squared_error

fxx = xx.flatten()
fyy = yy.flatten()
RMSDtruth = np.sqrt(mean_squared_error(fxx, fyy))
print("the real RMSE is", RMSDtruth)
コード例 #5
0
mil = 'init'

with open('model/additional_x') as f:
    additional = list(map(float, f.read().split('\n')))

while True:
    try:
        mil = float(input("Enter Milleage:"))
    except:
        print("Not float input, exiting")
        exit()

    try:
        mil_n = normalize_pred_x(mil, *additional)
    except:
        print("Retrain with suggested normalize!")
        exit()

    pred = a * mil_n + b
    real_norm_pred = real_norm_a * mil_n + real_norm_b
    real_pred = real_a * mil + real_b

    pred_d = denormalize(pred)
    real_norm_pred_d = denormalize(real_norm_pred)
    print("Predict : ", pred_d)
    print("Predict real normalized : ", real_norm_pred_d)
    print("Error real normalized : ", abs(real_norm_pred_d - pred_d))
    print("Predict real : ", real_pred)
    print("Error real : ", abs(real_pred - pred_d))