Commit 75c995c5 authored by Christoph Sommer's avatar Christoph Sommer

restucturing: most working

parent bfa286dd
......@@ -5,7 +5,15 @@ import pathlib
import ipywidgets as widgets
from functools import partial
from IPython.display import display
import warnings
warnings.filterwarnings("ignore")
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
from csbdeep.utils import plot_some
from .qt_file_dialog import gui_fname
from .qt_dir_dialog import gui_dirname
from .qt_filesave_dialog import gui_fsavename
......
......@@ -14,9 +14,11 @@ from skimage.transform import rescale
from tqdm import tqdm_notebook as tqdm
import warnings
warnings.simplefilter("ignore")
warnings.filterwarnings("ignore")
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
from csbdeep.utils import plot_some
from csbdeep.models import Config, CARE
from csbdeep.io import load_training_data
......@@ -27,11 +29,6 @@ from csbdeep.utils import axes_dict, plot_some, plot_history
from .utils import JVM, get_file_list, get_pixel_dimensions, \
get_upscale_factors, get_space_time_resolution, Timer
import warnings
warnings.filterwarnings("ignore")
tf.logging.set_verbosity(tf.logging.ERROR)
if type(tf.contrib) != type(tf): tf.contrib._warning = None
class CareInputConverter(object):
def __init__(self, **params):
......@@ -161,8 +158,8 @@ class CareTrainer(object):
n_channel_in, n_channel_out = X.shape[c], Y.shape[c]
config = Config(axes, n_channel_in, n_channel_out, train_epochs=self.train_epochs,
train_steps_per_epoch=self.train_steps_per_epoch,
train_batch_size=self.train_batch_size,
train_steps_per_epoch=self.train_steps_per_epoch,
train_batch_size=self.train_batch_size,
**config_args,)
# Training
model = CARE(config, 'CH_{}_model'.format(ch), basedir=pathlib.Path(self.out_dir) / 'models')
......@@ -171,9 +168,13 @@ class CareTrainer(object):
try:
history = model.train(X,Y, validation_data=(X_val,Y_val))
except tf.errors.ResourceExhaustedError:
print("ResourceExhaustedError: Aborting...\n Training data too big for GPU. Are other GPU jobs running? Perhaps, reduce batch-size or patch-size?")
print(" >> ResourceExhaustedError: Aborting...\n Training data too big for GPU. Are other GPU jobs running? Perhaps, reduce batch-size or patch-size?")
return
except tf.errors.UnknownError:
print(" >> UnknownError: Aborting...\n No enough memory available on GPU... are other GPU jobs running?")
return
#print(sorted(list(history.history.keys())))
plt.figure(figsize=(16,5))
plot_history(history,['loss','val_loss'],['mse','val_mse','mae','val_mae'])
......@@ -292,12 +293,15 @@ class CareTrainer(object):
description = """BIF-Care command line script for predicting new images given existing project."""
def get_args():
"""
Helper function for the argument parser.
"""
description = """CAREless care: command line script for predicting new images given existing project."""
parser = argparse.ArgumentParser(description=description)
# Add arguments
......@@ -305,11 +309,6 @@ def get_args():
parser.add_argument('files', type=str, nargs="+", help="Files to predict")
parser.add_argument('--ntiles', nargs=3, type=int, default=[1, 8, 8])
# parser.add_argument('-p', '-project', type=str, action='store', required=True, help="BIF-Care project file")
# parser.add_argument('-t', '-tiles' , type=str, action='store', default="1,4,4", help="Tiles in ZYX (default: 1,4,4)")
# parser.add_argument('files', type=str, nargs='+', help='Images to predict')
args = parser.parse_args()
return args
......
......@@ -4,8 +4,6 @@ import json
import glob
import time
import numpy
import warnings
warnings.simplefilter("ignore")
import pathlib
import tifffile
......@@ -13,6 +11,13 @@ import ipywidgets as widgets
from functools import partial
from IPython.display import display
import warnings
warnings.filterwarnings("ignore")
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
from ..care.qt_file_dialog import gui_fname
from ..care.qt_dir_dialog import gui_dirname
from ..care.qt_files_dialog import gui_fnames
......
......@@ -71,11 +71,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"metadata": {},
"source": [
"if project had been trained already, you can jump to section **4. Prediction** after loading the project file"
]
......@@ -112,7 +108,7 @@
"metadata": {},
"outputs": [],
"source": [
"#care.params.save()\n",
"care.params.save()\n",
"care.CareTrainer().create_patches()"
]
},
......
......@@ -176,6 +176,29 @@
"n2v.predict(files.value, n_tiles=(1,1,1))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tensorflow.__version__"
]
},
{
"cell_type": "code",
"execution_count": null,
......
......@@ -7,8 +7,8 @@ matplotlib>=2.1.2
tifffile>=2019.3.18
widgetsnbextension>=3.4.2
ipywidgets>=7.4.2
tensorflow-gpu>=1.12.0
tensorflow-gpu>=1.14.0
javabridge>=1.0.18
python-bioformats>=1.5.2
jupyterlab>=0.35.6
n2v==0.1.8
\ No newline at end of file
n2v==0.1.10
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment