Ejemplo n.º 1
0
    def get_opt(self, config, work_dir):
        opt = Options().parse(['--work_dir={}'.format(work_dir)])
        opt.work_dir = work_dir
        opt.input_size = 256
        opt.base_filter = int(config.get("base_filter"))
        opt.input_channels = []
        opt.target_channels = []
        # opt.load_from = None
        # opt.checkpoints_dir = opt.work_dir + "/__model__"

        inputs = config.get("inputs")
        outputs = config.get("outputs")
        # network = config.get("network")

        opt.channel = config.get("channel_config")
        for key in [input_key for input_key in opt.channel.keys() if input_key in inputs]:
            opt.input_channels.append(
                (opt.channel[key]["name"], {'filter': "*" + opt.channel[key]["filter"] + "*", 'loader': ImageLoader()},))

        for out in outputs:
            print("add target_channel:", out.get("name"))
            opt.target_channels.append((out.get("name"), {'filter': "*" + out.get("name") + "*", 'loader': ImageLoader()},))

        opt.input_nc = len(opt.input_channels)
        opt.target_nc = len(opt.target_channels)
        return opt
Ejemplo n.º 2
0
 async def run(self, my):
     targetObj = await api.showFileDialog(title="Please select a working directory (with data)")
     work_dir = targetObj.path
     api.setConfig('work_dir', work_dir)
     config = my.config
     print(config)
     opt = Options().parse(['--work_dir={}'.format(work_dir)])
     opt.work_dir = work_dir
     opt.input_size = config.input_size
     opt.base_filter = config.base_filter_num
     opt.input_channels = []
     for ch in config['input_ids'].split(','):
         name, filter = ch.split('=')
         opt.input_channels.append((name, {'filter':filter, 'loader':ImageLoader()}, ))
     opt.target_channels = []
     for ch in config['target_ids'].split(','):
         name, filter = ch.split('=')
         opt.target_channels.append((name, {'filter':filter, 'loader':ImageLoader()}, ))
     opt.input_nc = len(opt.input_channels)
     opt.target_nc = len(opt.target_channels)
     print(opt.input_channels, opt.target_channels)
     # opt.input_channels = [('cell', {'filter':'cells*.png', 'loader':ImageLoader()})]
     # opt.target_channels = [('mask', {'filter':'mask_edge*.png', 'loader':ImageLoader()})]
     self._opt = opt
     self.initialize(opt)
Ejemplo n.º 3
0
import os
import numpy as np
from anet.networks import UnetGenerator, get_dssim_l1_loss
from tensorflow.keras.callbacks import ModelCheckpoint, TensorBoard
from tensorflow.keras.models import load_model
from anet.data.examples import TransformedLRSR
from anet.options import Options
from anet.data.utils import make_generator
from anet.utils import export_model_to_js
# import importlib
# importlib.reload(UnetGenerator)

opt = Options().parse()
model = UnetGenerator(input_size=opt.input_size,
                      input_channels=opt.input_nc,
                      target_channels=opt.target_nc,
                      base_filter=16)

if opt.load_from is not None:
    model.load_weights(opt.load_from)

DSSIM_L1 = get_dssim_l1_loss()
model.compile(optimizer='adam', loss=DSSIM_L1, metrics=['mse', DSSIM_L1])

sources = TransformedLRSR(opt)

tensorboard = TensorBoard(log_dir=os.path.join(opt.checkpoints_dir, 'logs'),
                          histogram_freq=0,
                          batch_size=32,
                          write_graph=True,
                          write_grads=False,
Ejemplo n.º 4
0
import numpy as np
from anet.networks import UnetGenerator
from keras.losses import mean_absolute_error
from keras.callbacks import ModelCheckpoint
from anet.data.examples import TransformedTubulin001
from anet.options import Options
from anet.data.utils import make_generator

opt = Options().parse(['--work_dir=./results/__test__', '--batch_size=2'])
def test_train():
    model = UnetGenerator(image_size=opt.input_size, input_channels=opt.input_nc, target_channels=opt.target_nc, filters_base=16)
    model.compile(optimizer='adam',
                  loss=mean_absolute_error,
                  metrics=[mean_absolute_error])
    sources = TransformedTubulin001(opt)
    d = make_generator(sources['train'], batch_size=opt.batch_size)
    x, y = next(d)
    assert x.shape == (opt.batch_size, opt.input_size, opt.input_size, opt.input_nc)
    assert y.shape == (opt.batch_size, opt.target_size, opt.target_size, opt.target_nc)
    model.fit_generator(make_generator(sources['train'], batch_size=opt.batch_size),
                        validation_data=make_generator(sources['test'], batch_size=opt.batch_size),
                        validation_steps=1, steps_per_epoch=1, epochs=1, verbose=2, callbacks=[])
    import tensorflowjs as tfjs
    tfjs.converters.save_keras_model(model, opt.work_dir+'/__js_model__')
Ejemplo n.º 5
0
import numpy as np
from anet.options import Options
from anet.data.examples import GenericTransformedImages
from anet.data.file_loader import ImageLoader

from anet.networks import MobileUNet, get_dssim_l1_loss
from tensorflow.keras.callbacks import ModelCheckpoint, TensorBoard
from tensorflow.keras.models import load_model
from anet.data.examples import TransformedTubulin001
from anet.data.utils import make_generator, download_with_url
from anet.utils import export_model_to_js, UpdateUI

# import importlib
# importlib.reload(MobileUNet)

opt = Options().parse()
scale_factor = 0.5
opt.input_channels = [('bf1', {
    'filter': 'BF-10um.png',
    'loader': ImageLoader(scale=scale_factor)
}),
                      ('bf2', {
                          'filter': 'BF+10um.png',
                          'loader': ImageLoader(scale=scale_factor)
                      }),
                      ('nuclei', {
                          'filter': 'DAPI-MaxProj.png',
                          'loader': ImageLoader(scale=scale_factor)
                      })]
opt.target_channels = [('mebrane', {
    'filter': 'GFP.png',
Ejemplo n.º 6
0
from anet.networks import UnetGenerator, get_dssim_l1_loss
from tensorflow.keras.callbacks import ModelCheckpoint, TensorBoard
from tensorflow.keras.models import load_model
from anet.data.examples import TransformedTubulin001
from anet.data.utils import make_generator
from anet.utils import export_model_to_js

import tensorflow as tf
import json

from tensorflow.keras import backend as K
# import importlib
# importlib.reload(UnetGenerator)

opt = Options().parse()
# opt.work_dir = '/Users/weiouyang/ImJoyWorkspace/default/unet_data/train'
opt.input_channels = [('cell', {
    'filter': 'cells*.png',
    'loader': ImageLoader()
})]
opt.target_channels = [('mask', {
    'filter': 'mask_edge*.png',
    'loader': ImageLoader()
})]

model = UnetGenerator(input_size=opt.input_size,
                      input_channels=opt.input_nc,
                      target_channels=opt.target_nc,
                      base_filter=16)