Example #1
0
def test_tile_overlap(n_depth, kern_size):
    K.clear_session()
    img_size = 1280
    rf_x, rf_y = receptive_field_unet(n_depth, kern_size, 2, img_size)
    assert rf_x == rf_y
    rf = rf_x
    assert np.abs(rf[0] - rf[1]) < 10
    assert sum(rf) + 1 < img_size
    assert max(rf) == tile_overlap(n_depth, kern_size)
Example #2
0
def test_tile_overlap():
    n_depths = (1, 2, 3, 4, 5)
    n_kernel = (3, 5, 7)
    img_size = 1280
    for k in n_kernel:
        for n in n_depths:
            K.clear_session()
            rf_x, rf_y = receptive_field_unet(n, k, 2, img_size)
            assert rf_x == rf_y
            rf = rf_x
            assert np.abs(rf[0] - rf[1]) < 10
            assert sum(rf) + 1 < img_size
            assert max(rf) == tile_overlap(n, k)
Example #3
0
    def get_yml_dict(self,
                     name,
                     description,
                     authors,
                     test_img,
                     axes,
                     patch_shape=None):
        if (patch_shape != None):
            self.config.patch_shape = patch_shape
        ''' Repeated values to avoid reference tags of the form &id002 in yml output when the same variable is used more than
        once in the dictionary'''
        mean_val = []
        mean_val1 = []
        for ele in self.config.means:
            mean_val.append(float(ele))
            mean_val1.append(float(ele))
        std_val = []
        std_val1 = []
        for ele in self.config.stds:
            std_val.append(float(ele))
            std_val1.append(float(ele))
        in_data_range_val = ['-inf', 'inf']
        out_data_range_val = ['-inf', 'inf']

        axes_val = 'b' + self.config.axes
        axes_val = axes_val.lower()
        val = 2**self.config.unet_n_depth
        val1 = predict.tile_overlap(self.config.unet_n_depth,
                                    self.config.unet_kern_size)
        min_val = [1, val, val, self.config.n_channel_in]
        step_val = [1, val, val, 0]
        halo_val = [0, val1, val1, 0]
        scale_val = [1, 1, 1, 1]
        offset_val = [0, 0, 0, 3]

        yaml = YAML(typ='rt')
        with open(self.logdir / 'config.json', 'r') as f:
            tr_kwargs_val = yaml.load(f)

        if (self.config.n_dim == 3):
            min_val = [1, val, val, val, self.config.n_channel_in]
            step_val = [1, val, val, val, 0]
            halo_val = [0, val1, val1, val1, 0]
            scale_val = [1, 1, 1, 1, 1]
            offset_val = [0, 0, 0, 0, 0]

        yml_dict = {
            'name':
            name,
            'description':
            description,
            'cite': [{
                'text':
                'Tim-Oliver Buchholz and Mangal Prakash and Alexander Krull and Florian Jug DenoiSeg: Joint Denoising and Segmentation\nArXiv (2020)',
                'doi': 'arXiv:2005.02987'
            }],
            'authors':
            authors,
            'language':
            'python',
            'framework':
            'tensorflow',
            'format_version':
            '0.2.0-csbdeep',
            'source':
            'denoiseg',
            'test_input':
            'testinput.tif',
            'test_output':
            'testoutput.tif',
            'inputs': [{
                'name': 'input',
                'axes': axes_val,
                'data_type': 'float32',
                'data_range': in_data_range_val,
                'halo': halo_val,
                'shape': {
                    'min': min_val,
                    'step': step_val
                }
            }],
            'outputs': [{
                'name': self.keras_model.layers[-1].output.name,
                'axes': axes_val,
                'data_type': 'float32',
                'data_range': out_data_range_val,
                'shape': {
                    'reference_input': 'input',
                    'scale': scale_val,
                    'offset': offset_val
                }
            }],
            'training': {
                'source': 'n2v.train()',
                'kwargs': tr_kwargs_val
            },
            'prediction': {
                'weights': {
                    'source': './variables/variables'
                },
                'preprocess': [{
                    'kwargs': {
                        'mean': mean_val,
                        'stdDev': std_val
                    }
                }],
                'postprocess': [{
                    'kwargs': {
                        'mean': mean_val1,
                        'stdDev': std_val1
                    }
                }]
            }
        }

        return yml_dict
Example #4
0
    def get_yml_dict(self,
                     name,
                     description,
                     authors,
                     test_img,
                     axes,
                     patch_shape=None):
        if (patch_shape != None):
            self.config.patch_shape = patch_shape
        ''' Repeated values to avoid reference tags of the form &id002 in yml output when the same variable is used more than
        once in the dictionary'''
        mean_val = []
        mean_val1 = []
        for ele in self.config.means:
            mean_val.append(float(ele))
            mean_val1.append(float(ele))
        std_val = []
        std_val1 = []
        for ele in self.config.stds:
            std_val.append(float(ele))
            std_val1.append(float(ele))
        in_data_range_val = ['-inf', 'inf']
        out_data_range_val = ['-inf', 'inf']

        axes_val = 'b' + self.config.axes
        axes_val = axes_val.lower()
        val = 2**self.config.unet_n_depth
        val1 = predict.tile_overlap(self.config.unet_n_depth,
                                    self.config.unet_kern_size)
        min_val = [1, val, val, self.config.n_channel_in]
        step_val = [1, val, val, 0]
        halo_val = [0, val1, val1, 0]
        scale_val = [1, 1, 1, 1]
        offset_val = [0, 0, 0, 0]

        yaml = YAML(typ='rt')
        with open(self.logdir / 'config.json', 'r') as f:
            tr_kwargs_val = yaml.load(f)

        if (self.config.n_dim == 3):
            min_val = [1, val, val, val, self.config.n_channel_in]
            step_val = [1, val, val, val, 0]
            halo_val = [0, val1, val1, val1, 0]
            scale_val = [1, 1, 1, 1, 1]
            offset_val = [0, 0, 0, 0, 0]

        yml_dict = {
            'name':
            name,
            'description':
            description,
            'cite': [{
                'text':
                'Krull, A. and Buchholz, T. and Jug, F. Noise2void - learning denoising from single noisy images.\nProceedings of the IEEE Conference on Computer Vision and Pattern Recognition (2019)',
                'doi': '10.1109/CVPR.2019.00223'
            }],
            'authors':
            authors,
            'language':
            'python',
            'framework':
            'tensorflow',
            'format_version':
            '0.2.0-csbdeep',
            'source':
            'n2v',
            'test_input':
            'testinput.tif',
            'test_output':
            'testoutput.tif',
            'inputs': [{
                'name': 'input',
                'axes': axes_val,
                'data_type': 'float32',
                'data_range': in_data_range_val,
                'halo': halo_val,
                'shape': {
                    'min': min_val,
                    'step': step_val
                }
            }],
            'outputs': [{
                'name': self.keras_model.layers[-1].output.name,
                'axes': axes_val,
                'data_type': 'float32',
                'data_range': out_data_range_val,
                'shape': {
                    'reference_input': 'input',
                    'scale': scale_val,
                    'offset': offset_val
                }
            }],
            'training': {
                'source': 'n2v.train()',
                'kwargs': tr_kwargs_val
            },
            'prediction': {
                'weights': {
                    'source': './variables/variables'
                },
                'preprocess': [{
                    'kwargs': {
                        'mean': mean_val,
                        'stdDev': std_val
                    }
                }],
                'postprocess': [{
                    'kwargs': {
                        'mean': mean_val1,
                        'stdDev': std_val1
                    }
                }]
            }
        }

        return yml_dict