Commit 9c2f6361 authored by Christoph Sommer's avatar Christoph Sommer

restucturing project into careless

parent 478ce527
.ipynb_checkpoints/
.idea/
bif_care.egg-info/
build/
dist/
......
This diff is collapsed.
import os
import sys
import glob
import json
import numpy
import pathlib
import argparse
import tifffile
import javabridge as jv
import bioformats as bf
......@@ -31,7 +33,7 @@ warnings.filterwarnings("ignore")
tf.logging.set_verbosity(tf.logging.ERROR)
if type(tf.contrib) != type(tf): tf.contrib._warning = None
class BifCareInputConverter(object):
class CareInputConverter(object):
def __init__(self, **params):
self.order = 0
self.__dict__.update(**params)
......@@ -103,9 +105,12 @@ class BifCareInputConverter(object):
self._convert(self.high_wc, "GT")
print("Done")
class BifCareTrainer(object):
class CareTrainer(object):
def __init__(self, **params):
self.order = 0
if len(params) == 0:
from .care import params
self.__dict__.update(**params)
def create_patches(self):
......@@ -287,5 +292,58 @@ class BifCareTrainer(object):
description = """BIF-Care command line script for predicting new images given existing project."""
def get_args():
"""
Helper function for the argument parser.
"""
parser = argparse.ArgumentParser(description=description)
# Add arguments
parser.add_argument('--care_project', type=str, nargs=1, help="CAREless care project file (.json)", required=True)
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
def cmd_line():
from .care import GuiParams
args = get_args()
assert os.path.exists(args.care_project[0]), f"Project file '{args.care_project[0]}'' does not exist."
params = GuiParams()
params.load(args.care_project[0])
print("\n\nCAREless care parameters")
print("-"*50)
for k, v in params.items():
print("{:25s}: {}".format(k,v))
print("n-tiles:", args.ntiles)
print("\n")
for fn in args.files:
assert os.path.exists(fn), f"File for prediction {fn} does not exist"
print("Predicting Careless...")
bt = CareTrainer(**params)
for fn in args.files:
bt.predict(fn, n_tiles=args.ntiles)
JVM().shutdown()
......@@ -12,14 +12,13 @@ import tifffile
import ipywidgets as widgets
from functools import partial
from IPython.display import display
from bif_care.utils import BFListReader
from bif_care.qt_file_dialog import gui_fname
from bif_care.qt_dir_dialog import gui_dirname
from bif_care.qt_files_dialog import gui_fnames
from bif_care.qt_filesave_dialog import gui_fsavename
from bif_care.utils import get_pixel_dimensions, get_space_time_resolution, get_file_list, JVM
from bif_care.gui import GuiParams, select_project, select_train_paramter, select_file_to_predict
from ..care.qt_file_dialog import gui_fname
from ..care.qt_dir_dialog import gui_dirname
from ..care.qt_files_dialog import gui_fnames
from ..care.qt_filesave_dialog import gui_fsavename
from ..care.utils import BFListReader, get_pixel_dimensions, get_space_time_resolution, get_file_list, JVM
from ..care.care import GuiParams, select_project, select_train_paramter, select_file_to_predict
description = """Careless Noise2Void interface"""
......@@ -36,7 +35,7 @@ class GuiParamsN2V(GuiParams):
self['train_epochs'] = 40
self['train_steps_per_epoch'] = 100
self['train_batch_size'] = 16
self['n2v_perc_pix'] = 1.6
self['n2v_perc_pix'] = 0.198
self['n2v_patch_shape'] = []
self['n2v_neighborhood_radius'] = 5
self['augment'] = False
......@@ -226,7 +225,7 @@ def select_n2v_parameter():
### N2V perc pixel
###################
float_n2v_perc_pix = widgets.BoundedFloatText(min=0, max=100, step=0.1, value=params['n2v_perc_pix'])
float_n2v_perc_pix = widgets.BoundedFloatText(min=0, max=100, step=0.01, value=params['n2v_perc_pix'])
def on_n2v_perc_pix_change(change):
params['n2v_perc_pix'] = change.new
......@@ -441,15 +440,17 @@ def predict(files, n_tiles=(1,4,4), params=params):
def cmd_line():
import argparse
description = """CAREless Noise2Void: command line script for predicting new images given existing project."""
parser = argparse.ArgumentParser(description=description)
parser.add_argument('--n2v_project', type=str, nargs=1, help="BIF noise2void project file (.json)", required=True)
parser.add_argument('files', type=str, nargs="*", help="Files to process with noise2void")
parser.add_argument('--n2v_project', type=str, nargs=1, help="CAREless Noise2Void project file (.json)", required=True)
parser.add_argument('files', type=str, nargs="*", help="Files to process with Noise2Void")
parser.add_argument('--ntiles', nargs=3, type=int, default=[1, 8, 8])
parser.add_argument('--model_name', nargs=1, type=str, default=None)
args = parser.parse_args()
params.load(args.n2v_project[0])
print("\n\nBIF_N2V Parameters")
print("\n\CAREless Noise2Void parameters")
print("-"*50)
for k, v in params.items():
print("{:25s}: {}".format(k,v))
......
......@@ -4,8 +4,18 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# CARE user interface\n",
"---\n",
"# CARE-*less* care\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"source": [
"#### Usage\n",
"\n",
"A **code cell** will either:\n",
......@@ -22,7 +32,7 @@
"* Input images will be loaded with the Bioformats library (supports e. g. tif, czi, lsm, etc.)\n",
"* 2D, 3D and movies are supported.\n",
"* Each channel will be processed independently\n",
"* For more information visit the [BIF_CARE](https://github.com/sommerc/bif_care) or the [CARE](http://csbdeep.bioimagecomputing.com/) webpage"
"* For more information visit the [CARE-less](https://git.ist.ac.at/csommer/careless) or the [CARE](http://csbdeep.bioimagecomputing.com/) webpage"
]
},
{
......@@ -31,8 +41,7 @@
"metadata": {},
"outputs": [],
"source": [
"from bif_care import gui\n",
"from bif_care.core import BifCareTrainer"
"from careless.care import care"
]
},
{
......@@ -49,7 +58,7 @@
"metadata": {},
"outputs": [],
"source": [
"gui.select_project()"
"care.select_project()"
]
},
{
......@@ -60,13 +69,24 @@
"---"
]
},
{
"cell_type": "markdown",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"source": [
"if project had been trained already, you can jump to section **4. Prediction** after loading the project file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gui.select_input()"
"care.select_input()"
]
},
{
......@@ -83,7 +103,7 @@
"metadata": {},
"outputs": [],
"source": [
"gui.select_patch_parameter()"
"care.select_patch_parameter()"
]
},
{
......@@ -92,8 +112,8 @@
"metadata": {},
"outputs": [],
"source": [
"gui.params.save()\n",
"BifCareTrainer(**gui.params).create_patches()"
"#care.params.save()\n",
"care.CareTrainer().create_patches()"
]
},
{
......@@ -110,7 +130,7 @@
"metadata": {},
"outputs": [],
"source": [
"gui.select_train_paramter()"
"care.select_train_paramter()"
]
},
{
......@@ -119,8 +139,8 @@
"metadata": {},
"outputs": [],
"source": [
"gui.params.save()\n",
"BifCareTrainer(**gui.params).train()"
"care.params.save()\n",
"care.CareTrainer().train()"
]
},
{
......@@ -129,7 +149,7 @@
"source": [
"## 4. Prediction\n",
"---\n",
"**requires loaded and trained project**\n",
"**requires a loaded and trained project**\n",
"* Images will be tiled according to the **n_tiles** (z,y,x) parameter. (usefull for big images)"
]
},
......@@ -139,7 +159,7 @@
"metadata": {},
"outputs": [],
"source": [
"predict_file = gui.select_file_to_predict()"
"predict_file = care.select_file_to_predict()"
]
},
{
......@@ -148,7 +168,7 @@
"metadata": {},
"outputs": [],
"source": [
"BifCareTrainer(**gui.params).predict_multiple(predict_file.value, n_tiles=(1,4,4))"
"care.CareTrainer().predict_multiple(predict_file.value, n_tiles=(1,4,4))"
]
},
{
......@@ -179,5 +199,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
......@@ -4,8 +4,18 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Noise2void user interface\n",
"---\n",
"# CARE-*less* Noise2Void \n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"source": [
"#### Usage\n",
"\n",
"A **code cell** will either:\n",
......@@ -20,18 +30,20 @@
"* Input images will be loaded with the Bioformats library (supports e. g. tif, czi, lsm, etc.)\n",
"* 2D, 3D and movies are supported.\n",
"* Each channel will be processed independently\n",
"* For more information visit the [BIF_CARE](https://github.com/sommerc/bif_care) or the [N2V](https://github.com/juglab/n2v) webpage"
"* For more information visit the [CARE-less](https://git.ist.ac.at/csommer/careless) or the [N2V](https://github.com/juglab/n2v) webpage"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"pycharm": {
"is_executing": false
}
},
"outputs": [],
"source": [
"from bif_n2v import bif_n2v\n",
"# get_ipython().magic('reload_ext autoreload')\n",
"# get_ipython().magic('autoreload 2')"
"from careless.n2v import n2v"
]
},
{
......@@ -45,10 +57,14 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"pycharm": {
"is_executing": false
}
},
"outputs": [],
"source": [
"bif_n2v.select_project()"
"n2v.select_project()"
]
},
{
......@@ -62,10 +78,14 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"pycharm": {
"is_executing": false
}
},
"outputs": [],
"source": [
"bif_n2v.select_input()"
"n2v.select_input()"
]
},
{
......@@ -79,15 +99,19 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"pycharm": {
"is_executing": false
}
},
"outputs": [],
"source": [
"bif_n2v.select_channel()\n",
"bif_n2v.select_patch_parameter()\n",
"bif_n2v.select_npatch_per_image()\n",
"bif_n2v.select_augment()\n",
"bif_n2v.select_n2v_parameter()\n",
"bif_n2v.select_train_paramter()"
"n2v.select_channel()\n",
"n2v.select_patch_parameter()\n",
"n2v.select_npatch_per_image()\n",
"n2v.select_augment()\n",
"n2v.select_n2v_parameter()\n",
"n2v.select_train_paramter()"
]
},
{
......@@ -95,7 +119,17 @@
"metadata": {},
"source": [
"## 3. Denoise (train and predict)\n",
"---\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"source": [
"* Images will be tiled according to the **n_tiles** (z,y,x) parameter. (usefull for big images)\n",
"* For advanced training parameters type and execute *bif_n2v.train_predict?* in an empty code cell"
]
......@@ -103,11 +137,15 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"pycharm": {
"is_executing": false
}
},
"outputs": [],
"source": [
"bif_n2v.params.save()\n",
"a = bif_n2v.train_predict(n_tiles=(1,8,8))"
"n2v.params.save()\n",
"a = n2v.train_predict(n_tiles=(1,1,1))"
]
},
{
......@@ -126,7 +164,7 @@
"metadata": {},
"outputs": [],
"source": [
"files = bif_n2v.select_file_to_predict()"
"files = n2v.select_file_to_predict()"
]
},
{
......@@ -135,16 +173,7 @@
"metadata": {},
"outputs": [],
"source": [
"bif_n2v.predict(files.value, n_tiles=(1,4,4))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bif_n2v.params.save()"
"n2v.predict(files.value, n_tiles=(1,1,1))"
]
},
{
......@@ -172,8 +201,17 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
},
"pycharm": {
"stem_cell": {
"cell_type": "raw",
"metadata": {
"collapsed": false
},
"source": []
}
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
import re
from setuptools import setup
with open("README.md", "rb") as f:
description = f.read().decode("utf-8")
setup(
name = "bif_care",
packages = ["bif_care"],
version = "0.2",
name = "CAREless",
packages = ["careless"],
version = "0.3",
description = description,
long_description = description,
entry_points = {'console_scripts': ['bif_n2v=bif_n2v.bif_n2v:cmd_line']},
entry_points = {'console_scripts': ['careless_n2v=careless.n2v.n2v:cmd_line',
'careless_Care=careless.care.core:cmd_line',
]},
author = "Christoph Sommer",
author_email = "christoph.sommer23@gmail.com",
)
\ 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