Пример #1
0
def predict_on_fullimage(test_set_x,params):
    model= model_provider.get_model_pretrained(params)
    # learning parameters
    batch_size =params["batch_size"]
    n_test_batches = len(test_set_x)
    ash=n_test_batches%batch_size
    if(ash>0):
        test_set_x=np.vstack((test_set_x,np.tile(test_set_x[-1],(batch_size-ash,1))))
        n_test_batches = len(test_set_x)

    n_test_batches /= batch_size
    y_pred=[]
    print("Number of parameters: %s"%(model.count_params()))
    print "Prediction on test images"
    patch_loc=u.get_patch_loc(params) #we are not using this for image
    map_index=0
    for i in xrange(n_test_batches):
        Fx = test_set_x[i * batch_size: (i + 1) * batch_size]
        argu= [(params,"F", Fx,patch_loc,map_index),(params,"S", Fx,patch_loc,map_index)]
        results = du.asyn_load_batch_images(argu)
        data_Fx = results[0]
        data_Sx = results[1]
        if(params["model_type"]==4):
            data=data_Sx-data_Fx
            res =model.predict(data)
        else:
            res=model.predict([data_Fx, data_Sx])
        if(len(y_pred)==0):
            y_pred= res
        else:
            y_pred=np.concatenate((y_pred,res))
    if(ash>0):
        y_pred= y_pred[0:-(batch_size-ash)]
    return y_pred
Пример #2
0
def predict_on_multi_input(test_set_x,params):
    model= model_provider.get_model_pretrained(params)
    # learning parameters
    batch_size =params["batch_size"]
    n_test_batches = len(test_set_x)
    ash=n_test_batches%batch_size
    if(ash>0):
        test_set_x=np.vstack((test_set_x,np.tile(test_set_x[-1],(batch_size-ash,1))))
        n_test_batches = len(test_set_x)

    n_test_batches /= batch_size
    y_pred=[]
    pred_mat={}
    print "Prediction on test images"
    n_patch=params["n_patch"]
    n_repeat=params["n_repeat"]

    map_list=range(batch_size*n_repeat)
    n=n_patch*n_repeat
    for i in xrange(n_test_batches):
        map_index=map_list[i]%n_repeat
        Fx = test_set_x[i * batch_size: (i + 1) * batch_size]
        pred=np.zeros((batch_size,params['n_output']))
        pred_mat[0]=np.zeros((n,params['n_output']))
        for k in range(batch_size): pred_mat[k+i]=np.zeros((n,params['n_output']))
        for patch_index in xrange(n):
            patch_loc=u.get_patch_loc(params)
            argu= [(params,"F", Fx,patch_loc,map_index),(params,"S", Fx,patch_loc,map_index)]
            results = du.asyn_load_batch_images(argu)
            data_Fx = results[0]
            data_Sx = results[1]
            prd=model.predict([data_Fx, data_Sx])
            for j in range(len(prd)):
                pred_mat[i+j][patch_index]=prd[j]
            pred=np.add(pred, prd)


        pred/=n
        if(len(y_pred)==0):
            y_pred= pred
        else:
            y_pred=np.concatenate((y_pred,pred))
    pd.plot_patch(pred_mat)
    if(ash>0):
        y_pred= y_pred[0:-(batch_size-ash)]
    return y_pred
Пример #3
0
    paddedw = imshape[1] + border
    for i in xrange(nimgs):
        row = int(np.floor(i / ncols))
        col = i % ncols

        mosaic[row * paddedh : row * paddedh + imshape[0], col * paddedw : col * paddedw + imshape[1]] = imgs[i]
    return mosaic


# pl.imshow(make_mosaic(np.random.random((9, 10, 10)), 3, 3, border=1))

params = config.get_params()
params["model_name"] = "more_noreg_data2_46_gray.hdf5"
params["model"] = "kcnnr"

model = mp.get_model_pretrained(params)


for i in range(2):
    print("Lef or right: %s th" % (i))
    for k in range(3):
        print("Layer param:of %s th" % (i))
        # Visualize weights
        W = np.squeeze(model.layers[0].layers[i].layers[k * 3].W.get_value(borrow=True))
        print("W shape : ", W.shape)
        pl.figure(figsize=(15, 15))
        pl.title("conv1 weights (i,k)(%s,%s)" % (i, k))
        if len(W.shape) > 3:
            X = W.reshape(W.sahpe[0], 20, 30)
            mosaic = make_mosaic(X, 6, 6)
            nice_imshow(pl.gca(), mosaic, cmap=cm.binary)