Ejemplo n.º 1
0
def test_model_projection_predict(tmpdir, config):
    rng = np.random.RandomState(42)

    K.clear_session()
    model = ProjectionCARE(config, basedir=None)
    axes = config.axes
    proj_axis = model.proj_params.axis

    def _predict(imdims, axes):
        img = rng.uniform(size=imdims)
        n_tiles = [1] * len(axes)
        ax = axes_dict(axes)

        if config.probabilistic:
            prob = model.predict_probabilistic(img, axes, None, None)
            mean, scale = prob.mean(), prob.scale()
            assert mean.shape == scale.shape
        else:
            mean = model.predict(img, axes, None, None)

            n_tiles[ax['X']] = 3
            n_tiles[ax['Y']] = 2
            mean_tiled = model.predict(img, axes, None, None, n_tiles=n_tiles)
            error_max = np.max(np.abs(mean - mean_tiled))
            # print(n_tiles, error_max)
            assert error_max < 1e-3

            with pytest.raises(ValueError):
                n_tiles[ax[proj_axis]] = 2
                model.predict(img, axes, None, None, n_tiles=n_tiles)

        shape_out = list(imdims)
        if 'C' in axes:
            shape_out[ax['C']] = config.n_channel_out
        elif config.n_channel_out > 1:
            shape_out.append(config.n_channel_out)

        del shape_out[ax[proj_axis]]
        assert tuple(shape_out) == mean.shape

    imdims = list(rng.randint(30, 50, size=config.n_dim))
    # imdims = [10,1024,1024]
    imdims = [(d // div_n) * div_n
              for d, div_n in zip(imdims, model._axes_div_by(axes))]

    if config.n_channel_in == 1:
        _predict(imdims, axes=axes.replace('C', ''))

    channel = rng.randint(0, config.n_dim)
    imdims.insert(channel, config.n_channel_in)
    _axes = axes.replace('C', '')
    _axes = _axes[:channel] + 'C' + _axes[channel:]
    _predict(imdims, axes=_axes)
Ejemplo n.º 2
0
basedirResults3D = basedir + '/Restored'
basedirResults2D = basedir + '/Projected'
basedirResults3Dextended = basedirResults3D + '/Restored'
basedirResults2Dextended = basedirResults2D + '/Projected'

Model_Dir = '/run/media/sancere/DATA/Lucas_Model_to_use/CARE/'

# In[3]:

RestorationModel = 'CARE_restoration_Borealis_Bin1'
ProjectionModel = 'CARE_projection_Borealis_Bin1'

RestorationModel = CARE(config=None, name=RestorationModel, basedir=Model_Dir)
ProjectionModel = ProjectionCARE(config=None,
                                 name=ProjectionModel,
                                 basedir=Model_Dir)

# In[5]:

Path(basedirResults3D).mkdir(exist_ok=True)
Path(basedirResults2D).mkdir(exist_ok=True)

Raw_path = os.path.join(basedir, '*TIF')  #tif or TIF be careful

axes = 'ZYX'  #projection axes : 'YX'

filesRaw = glob.glob(Raw_path)

# In[6]:
Ejemplo n.º 3
0
                n_channel_out,
                unet_n_depth=4,
                train_epochs=50,
                train_steps_per_epoch=400,
                train_batch_size=16,
                train_reduce_lr={
                    'patience': 5,
                    'factor': 0.5
                })
print(config)
vars(config)

# In[5]:

model = ProjectionCARE(
    config,
    'DrosophilaDenoisingProjection',
    basedir='/local/u934/private/v_kapoor/CurieDeepLearningModels')

# In[6]:

history = model.train(X, Y, validation_data=(X_val, Y_val))

# In[7]:

# In[8]:

# In[9]:

model.export_TF()
Ejemplo n.º 4
0
basedirResults3D = basedir + '/Restored'
basedirResults2D = basedir + '/Projected'
basedirResults3Dextended = basedirResults3D + '/Restored'
basedirResults2Dextended = basedirResults2D + '/Projected'

Model_Dir = '/run/media/sancere/DATA/Lucas_Model_to_use/CARE/'
#Test_change_email_adress_to_see_commit

# In[3]:

RestorationModel = 'CARE_restoration_SpinWideFRAP4_Bin1_3Gfp'
ProjectionModel = 'CARE_projection_SpinWideFRAP4_Bin1_3Gfp'

RestorationModel = CARE(config=None, name=RestorationModel, basedir=Model_Dir)
ProjectionModel = ProjectionCARE(config=None,
                                 name=ProjectionModel,
                                 basedir=Model_Dir)

# In[5]:

#Path(basedirResults3D).mkdir(exist_ok = True)
Path(basedirResults2D).mkdir(exist_ok=True)

Raw_path = os.path.join(basedir, '*TIF')  #tif or TIF be careful

axes = 'ZYX'  #projection axes : 'YX'

filesRaw = glob.glob(Raw_path)

# In[6]:
                          n_channel_in,
                          n_channel_out,
                          unet_n_depth=4,
                          train_epochs=150,
                          train_steps_per_epoch=120,
                          train_batch_size=100,
                          train_reduce_lr={
                              'patience': 5,
                              'factor': 0.5
                          })
print(config)
vars(config)

# In[5]:

model = ProjectionCARE(config=config, name=ModelName, basedir=BaseDir)
# model.load_weights(ModelDir + 'CARE_projection_Borealis_Bin2_AudeData_Second' + '/' + 'weights_best.h5')

# In[6]:

history = model.train(X, Y, validation_data=(X_val, Y_val))

# In[7]:

# In[8]:

# In[9]:

model.export_TF()

# In[ ]:
Ejemplo n.º 6
0
from tifffile import imread
from csbdeep.utils import Path, download_and_extract_zip_file, plot_some
from csbdeep.io import save_tiff_imagej_compatible
from csbdeep.models import ProjectionCARE

# In[2]:

basedirLow = '/local/u934/private/v_kapoor/ProjectionTraining/MasterLow/NotsoLow/'
basedirResults = '/local/u934/private/v_kapoor/ProjectionTraining/MasterLow/NetworkProjections'
ModelName = 'DrosophilaDenoisingProjection'
BaseDir = '/local/u934/private/v_kapoor/CurieDeepLearningModels/'

# In[3]:

model = ProjectionCARE(config=None, name=ModelName, basedir=BaseDir)

# In[4]:

Raw_path = os.path.join(basedirLow, '*tif')
Path(basedirResults).mkdir(exist_ok=True)
axes = 'ZYX'
filesRaw = glob.glob(Raw_path)
filesRaw.sort
for fname in filesRaw:
    x = imread(fname)
    print('Saving file' + basedirResults + '%s_' + os.path.basename(fname))
    restored = model.predict(x, axes, n_tiles=(1, 4, 4))
    axes_restored = axes.replace(model.proj_params.axis, '')
    save_tiff_imagej_compatible(
        (basedirResults + '%s_' + os.path.basename(fname)) % model.name,