Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sami's Developpement #4

Open
wants to merge 152 commits into
base: Dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 120 commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
05bb833
Modified path to CONFIG from biom3d.configs.unet_default to biom3d.co…
SafarbatiSami Apr 18, 2023
6328037
Update README.md
SafarbatiSami Apr 19, 2023
62c716b
Merged Preprocessing Tab and Train tab.
SafarbatiSami Apr 19, 2023
14309eb
Merge branch 'main' of https://github.com/SafarbatiSami/biom3d into main
SafarbatiSami Apr 19, 2023
5423e0e
Added autoConfig in Preprocess_autoconfig() ;
SafarbatiSami Apr 19, 2023
2259dac
Merge remote-tracking branch 'upstream/main' into main
SafarbatiSami Apr 21, 2023
73a9e13
Changed dataType of aug_patch_size, patch_size, num_pools to Lists.
SafarbatiSami Apr 21, 2023
e4d69ab
Correction of train bug
SafarbatiSami Apr 24, 2023
54d0686
Modified Remote interface.
SafarbatiSami Apr 27, 2023
4d2707b
.
SafarbatiSami May 9, 2023
06e41ad
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami May 9, 2023
a627343
Added Parameters_return() function to Display config parameters.
SafarbatiSami May 10, 2023
98141f8
Changes in Remote functioning.
SafarbatiSami May 15, 2023
8c99ae7
Redefined dropdown Menus.
SafarbatiSami May 16, 2023
46cade7
Added Remote parameter.
SafarbatiSami May 16, 2023
536b7f9
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami May 16, 2023
7ffa3ce
added a popup message
SafarbatiSami Jun 2, 2023
308e464
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Jun 2, 2023
abc363d
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Jun 2, 2023
2a73681
Added fg_dir parameter
SafarbatiSami Jun 5, 2023
9cc40d3
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Jun 5, 2023
295e86d
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Jun 5, 2023
a41fde3
modified preprocess for remote
SafarbatiSami Jun 6, 2023
b4417de
correction for folder selection
SafarbatiSami Jun 6, 2023
954f64d
Changes for window size
SafarbatiSami Jun 7, 2023
9734cb4
correction for config path bug
SafarbatiSami Jun 7, 2023
9cb0d7a
train bugfix
SafarbatiSami Jun 7, 2023
49f8580
number of classes bugfix
SafarbatiSami Jun 7, 2023
b90174e
Changed save dir for configs
SafarbatiSami Jun 8, 2023
0c4cfba
changed save dir for configs
SafarbatiSami Jun 8, 2023
7a66ba1
Bugfix remote cfg load/save
SafarbatiSami Jun 9, 2023
372d898
File to generate the executbale file
SafarbatiSami Jun 16, 2023
4094949
Download prediction bugfix
SafarbatiSami Jun 16, 2023
08fcda4
correction popupmsg
SafarbatiSami Jun 16, 2023
5c52e12
Restricted access for local interface while using an executable
SafarbatiSami Jun 16, 2023
a1ad594
Modified Button positions
SafarbatiSami Jun 19, 2023
28992c6
Script to deploy an executable file for User interface
SafarbatiSami Jun 19, 2023
9e431fd
Correction for UI
SafarbatiSami Jun 20, 2023
ce1d571
Added Home button, modified positions for config parameters
SafarbatiSami Jun 20, 2023
094b743
Corrections for Gui
SafarbatiSami Jun 20, 2023
b5196a1
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Jun 20, 2023
df29091
changed the way to get auto config results
SafarbatiSami Jun 21, 2023
51ce3a3
Code Cleaning
SafarbatiSami Jun 21, 2023
24e69c9
Module to upload predictions in OMERO
SafarbatiSami Jun 22, 2023
684ed46
improved Uploader
SafarbatiSami Jun 23, 2023
83aa459
Added option to send prediction to OMERO
SafarbatiSami Jun 23, 2023
c7fa9b3
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Jun 23, 2023
0952279
improve Omero ulpoad
SafarbatiSami Jul 3, 2023
24877d2
Added loop to do all sub folders
SafarbatiSami Jul 5, 2023
017b161
update
SafarbatiSami Jul 20, 2023
35cf7f8
Removed CLI connection.
SafarbatiSami Jul 25, 2023
8594219
Updated Gui
SafarbatiSami Jul 25, 2023
b203812
update
SafarbatiSami Jul 25, 2023
cafd069
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Jul 26, 2023
c523288
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Jul 26, 2023
3845b38
Added project output id for omero
SafarbatiSami Jul 26, 2023
48b08c2
Added venv activation while using remote
SafarbatiSami Aug 7, 2023
8989cc4
train loss function plot (still working on it)
SafarbatiSami Aug 8, 2023
238d190
Added training curves
SafarbatiSami Aug 9, 2023
4491d00
updated learning curves
SafarbatiSami Aug 10, 2023
54e1fee
update
SafarbatiSami Aug 10, 2023
32ac5d9
Correction for leaning curves
SafarbatiSami Aug 11, 2023
7f194b0
changes in buttons size
SafarbatiSami Aug 14, 2023
3616305
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Aug 14, 2023
2db9c69
Update for GUI
SafarbatiSami Aug 14, 2023
560aa99
update gui
SafarbatiSami Aug 16, 2023
5fa81cd
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Aug 16, 2023
cd77277
blitz bugfix
SafarbatiSami Aug 16, 2023
0021bac
update gui
SafarbatiSami Aug 16, 2023
7da89c2
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Aug 16, 2023
745a294
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Aug 17, 2023
733d72c
Revert "Merge branch 'main' of https://github.com/GuillaumeMougeot/bi…
SafarbatiSami Aug 17, 2023
831f14c
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Aug 18, 2023
a524bb3
dataset update bugfix
SafarbatiSami Aug 18, 2023
202050c
Final GUI (maybe)
SafarbatiSami Aug 18, 2023
5c4f783
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Aug 18, 2023
db3255d
number of classes bugfix
SafarbatiSami Aug 18, 2023
290c259
plot bugfix
SafarbatiSami Aug 18, 2023
e7967ed
Learning curve Bugfix
SafarbatiSami Aug 18, 2023
2d67a74
Merge branch 'main' of https://github.com/SafarbatiSami/biom3d into main
SafarbatiSami Sep 8, 2023
53e6d5b
Added Objects filtering for prediction in GUI
SafarbatiSami Sep 11, 2023
56fafa9
Learning curves bufix
SafarbatiSami Sep 11, 2023
46099d8
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Sep 11, 2023
adc9728
Added option to use a config file for training
SafarbatiSami Sep 13, 2023
d994745
Added function descriptions, added option to choose where to store l…
SafarbatiSami Sep 15, 2023
b4cc422
Code Cleaning, removed useless stuff
SafarbatiSami Sep 18, 2023
25a353c
Added some doc
SafarbatiSami Sep 19, 2023
af289fc
Error handling
SafarbatiSami Sep 20, 2023
e0d85a7
Added Ressources computing
SafarbatiSami Sep 21, 2023
ca8b053
Removed useless imports
SafarbatiSami Sep 22, 2023
1a80e74
modified import
SafarbatiSami Sep 22, 2023
c8f5097
Windows path Bugfix
SafarbatiSami Sep 25, 2023
d4cc139
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Sep 25, 2023
2a8df11
error handling
SafarbatiSami Sep 25, 2023
0e9121f
text modification
SafarbatiSami Sep 26, 2023
7d234e1
text correction
SafarbatiSami Sep 26, 2023
bca58f7
text correction
SafarbatiSami Sep 26, 2023
54167f7
text correction
SafarbatiSami Sep 26, 2023
8226105
Added Fine tuning in local
SafarbatiSami Oct 2, 2023
9d34ae8
Added 3 display modes, added fine-tuning in local & remote
SafarbatiSami Oct 3, 2023
f4a73f9
Remote fine tuning update
SafarbatiSami Oct 4, 2023
bcebf96
classes bugfix, path bugfix
SafarbatiSami Oct 10, 2023
dbd7487
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Oct 10, 2023
2f79d78
Corrections for Local Path
SafarbatiSami Oct 30, 2023
bf6a17a
updated gui
SafarbatiSami Dec 19, 2023
baa3735
Documentation( en cours)
SafarbatiSami Dec 20, 2023
e446ce5
Trainers documentation
SafarbatiSami Dec 20, 2023
12a300d
Predictors Documentation
SafarbatiSami Dec 20, 2023
591494d
Semseg_torchio Documentation
SafarbatiSami Dec 20, 2023
89820ac
Semseg_patch_fast Documentation
SafarbatiSami Dec 20, 2023
7ff6988
Semseg_Batchgen Documentation
SafarbatiSami Dec 20, 2023
67d0eff
Added browse button in splash screen
SafarbatiSami Dec 21, 2023
e5b5255
Added Biom3d logo to the Gui
SafarbatiSami Dec 21, 2023
44302bf
Adapted preprocessing for 2d images
SafarbatiSami Mar 21, 2024
78269d2
added doc
SafarbatiSami Mar 21, 2024
ee3bf77
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Mar 21, 2024
b3ddcb6
version 0.0.38
GuillaumeMougeot Mar 27, 2024
cedc40b
implementation of 2d segmentation
SafarbatiSami Apr 12, 2024
d56cc6d
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Apr 12, 2024
aec59e1
Bufix arborescence upload, added attachement file to omero upload
SafarbatiSami Apr 17, 2024
095650f
Inverted Z & T bugfix
SafarbatiSami Apr 26, 2024
09f77e6
Corrections for PR
SafarbatiSami Jun 13, 2024
409d7cc
corrected is2d to is_2d
SafarbatiSami Jun 17, 2024
733c482
Added Model as upload File in OMERO
SafarbatiSami Jun 19, 2024
2ff92b2
Data managment after OMERO prediction
SafarbatiSami Jun 19, 2024
9119cba
Module for training with OMERO data
SafarbatiSami Jun 19, 2024
a14f26d
Updated GUI ( Omero Training, Omero Pred ...)
SafarbatiSami Jun 19, 2024
e404288
latest tests
GuillaumeMougeot Jun 25, 2024
bccc3b3
preprocessing - minor fix for 4-dimensional masks
GuillaumeMougeot Jun 25, 2024
fca5e68
minor fix on preprocessing
GuillaumeMougeot Jun 25, 2024
b0684d7
Removed torch version in dependency for Colab.
GuillaumeMougeot Jun 28, 2024
3bc7acb
updated version in Colab
GuillaumeMougeot Jun 28, 2024
725aa85
added efficientUnet
GuillaumeMougeot Jul 5, 2024
acddb1d
added efficientUnet in register
GuillaumeMougeot Jul 5, 2024
11e0491
removed useless comments
GuillaumeMougeot Jul 5, 2024
cdd09f6
updated colab for torchio
GuillaumeMougeot Jul 8, 2024
76869bd
Omero connection with session id
SafarbatiSami Jul 8, 2024
3bd5b28
Merge branch 'main' of https://github.com/GuillaumeMougeot/biom3d int…
SafarbatiSami Jul 8, 2024
84ddbb5
updated Omero preprocess_train ( now uploads training images)
SafarbatiSami Jul 9, 2024
05b6ece
Added Omero upload after training in GUI
SafarbatiSami Jul 9, 2024
6e11ec3
num_worker to 1
SafarbatiSami Jul 11, 2024
c488dce
Changed num_workers to 8
SafarbatiSami Jul 15, 2024
bf1fa04
removed try catch for omero_uploader
SafarbatiSami Jul 17, 2024
1edd81f
changed num of workers back to 6
SafarbatiSami Jul 17, 2024
c26e351
removed useless import
SafarbatiSami Jul 17, 2024
8884ef9
Merge branch '2D_Segmentation' of https://github.com/SafarbatiSami/bi…
SafarbatiSami Jul 17, 2024
cacc806
Adapted omero uploader to use session id
SafarbatiSami Jul 18, 2024
4e052ed
Added File annotation download
SafarbatiSami Jul 22, 2024
ed9ef6d
Adapted omero uploader for omero_preprocess_train
SafarbatiSami Jul 22, 2024
80c1b5e
Added learning curves plot, Added autoconfig, train
SafarbatiSami Jul 22, 2024
295b099
Correction for omero session bug
SafarbatiSami Jul 23, 2024
e48bc68
Added prediction for omero_preprocess_train
SafarbatiSami Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bash/deploy_win64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# create a venv :
python -m venv NAME_OF_YOUR_VIRTUAL_ENV
# then install :
pip install pyinstaller python-tk numpy SimpleITK scikit-image tqdm paramiko pyyaml matplotlib
# run the pyinstaller (with console) and exclude modules
pyinstaller -F --clean --upx-dir PATH_TO_UPX PATH_TO_GUI\gui.py --exclude=biom3d --exclude=torch --hidden-import='PIL._tkinter_finder'
Binary file added docs/_static/image/gui_remote_predict.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/image/gui_remote_predict_omero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/_static/image/gui_remote_train.PNG
Binary file not shown.
Binary file added docs/_static/image/gui_remote_train.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/image/gui_splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions docs/quick_run_gui.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ Biom3d comes with 2 modes: local or remote. 'Local' means that the computation w

If you have installed biom3d with the local version simply click on the 'Start locally' button to start, you can choose a path to store your files in the field over the button, by default, the files are stored in the directory where biom3d have been launched.

<<<<<<< HEAD
If you have installed biom3d with the remote version, you must then complete the required fields. The first one is the IP address of your remote computer (where the API of biom3d is installed). The second and third one is your user name and password to connect to the remote computer, the forth one is the path to your virtual environment (if you don't have a virtual environment leave it empty ).
=======
If you have installed biom3d with the remote version, you must then complete the required fields. The first one is the IP address of your remote computer (where the API of biom3d is installed). The second and third one is your user name and password to connect to the remote computer, the forth one is the path to your virtual environment (if you don't have a virtual environment leave it empty).
>>>>>>> f562750641a74b960ed698e427ed811313552d0e


## Preprocess & Train
Expand Down
Binary file added logo_biom3d_crop.ico
Binary file not shown.
48 changes: 43 additions & 5 deletions src/biom3d/auto_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def compute_median(path, return_spacing=False):
for i in range(len(path_imgs)):

img,metadata = adaptive_imread(path_imgs[i])
# Check if the image is 2D (has two dimensions)
if len(img.shape) == 2:
# Add a third dimension with size 1 to make it 3D
img = np.expand_dims(img, axis=0)
spacing = None if not 'spacing' in metadata.keys() else metadata['spacing']

assert len(img.shape)>0, "[Error] Wrong image image."
Expand Down Expand Up @@ -91,6 +95,10 @@ def data_fingerprint(img_dir, msk_dir=None, num_samples=10000):

for i in range(len(path_imgs)):
img,metadata = adaptive_imread(path_imgs[i])
# Check if the image is 2D (has two dimensions)
if len(img.shape) == 2:
# Add a third dimension with size 1 to make it 3D
img = np.expand_dims(img, axis=0)
spacing = None if not 'spacing' in metadata.keys() else metadata['spacing']

# store the size
Expand All @@ -103,6 +111,10 @@ def data_fingerprint(img_dir, msk_dir=None, num_samples=10000):
if msk_dir is not None:
# read msk
msk,_ = adaptive_imread(path_msks[i])
# Check if the image is 2D (has two dimensions)
if len(msk.shape) == 2:
# Add a third dimension with size 1 to make it 3D
msk = np.expand_dims(msk, axis=0)

# extract only useful voxels
img = img[msk > 0]
Expand Down Expand Up @@ -151,7 +163,7 @@ def find_patch_pool_batch(dims, max_dims=(128,128,128), max_pool=5, epsilon=1e-3
batch: numpy.ndarray
Batch size.
"""
# transform tuples into arrays
# transform tuples into arrays
assert len(dims)==3 or len(dims)==4, print("Dims has not the correct number of dimensions: len(dims)=", len(dims))
if len(dims)==4:
dims=dims[1:]
Expand Down Expand Up @@ -279,15 +291,23 @@ def get_aug_patch(patch_size):

# ----------------------------------------------------------------------------
# Display
def parameters_return(patch, pool, batch, config_path):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a quoi sert cette fonction? documentation

print(batch)
print(patch)
aug_patch= get_aug_patch(patch)
print(aug_patch)
print(pool)
print(config_path)

def display_info(patch, pool, batch):
"""Print in terminal the patch size, the number of pooling and the batch size.
"""

print("*"*20,"YOU CAN COPY AND PASTE THE FOLLOWING LINES INSIDE THE CONFIG FILE", "*"*20)
print("BATCH_SIZE =", batch)
print("PATCH_SIZE =", list(patch))
aug_patch = get_aug_patch(patch)
print("AUG_PATCH_SIZE =",list(aug_patch))
print("AUG_PATCH_SIZE =",list(aug_patch))
print("NUM_POOLS =", list(pool))

def auto_config(img_dir=None, median=None, max_dims=(128,128,128), max_batch=16, min_batch=2):
Expand Down Expand Up @@ -342,6 +362,8 @@ def auto_config(img_dir=None, median=None, max_dims=(128,128,128), max_batch=16,
help="(default=\'configs/\') Configuration folder to save the auto-configuration.")
parser.add_argument("--base_config", type=str, default=None,
help="(default=None) Optional. Path to an existing configuration file which will be updated with the preprocessed values.")
parser.add_argument("--remote", default=False, dest='remote',
help="Use this arg when using remote autoconfing only")
args = parser.parse_args()

median = compute_median(path=args.img_dir, return_spacing=args.spacing)
Expand All @@ -353,8 +375,24 @@ def auto_config(img_dir=None, median=None, max_dims=(128,128,128), max_batch=16,
patch, pool, batch = find_patch_pool_batch(dims=median, max_dims=(args.max_dim, args.max_dim, args.max_dim))
aug_patch = np.array(patch)+2**(np.array(pool)+1)

display_info(patch, pool, batch)


if args.remote:
try:
from biom3d.utils import save_python_config
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplica avec lignes 401 à 411. peut être essayer de compresser

config_path = save_python_config(
config_dir=args.config_dir,
base_config=args.base_config,
BATCH_SIZE=batch,
AUG_PATCH_SIZE=aug_patch,
PATCH_SIZE=patch,
NUM_POOLS=pool,
)
parameters_return(patch, pool, batch, config_path)
except:
print("[Error] Import error. Biom3d must be installed if you want to save your configuration. Another solution is to config the function function in biom3d.utils here...")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

faute d'orthographe

raise ImportError
else :
display_info(patch, pool, batch)
if args.spacing:print("MEDIAN_SPACING =",list(median_spacing))
if args.median:print("MEDIAN =", list(median))

Expand All @@ -375,4 +413,4 @@ def auto_config(img_dir=None, median=None, max_dims=(128,128,128), max_batch=16,
print("[Error] Import error. Biom3d must be installed if you want to save your configuration. Another solution is to config the function function in biom3d.utils here...")
raise ImportError

# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
2 changes: 1 addition & 1 deletion src/biom3d/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def run_prediction_single(self, img_path=None, img=None, img_meta=None, return_l
**img_meta) # all img_meta should be equal as we use the same preprocessors

else: # single model prediction
img, img_meta = read_config(self.config.PREPROCESSOR, register.preprocessors, img=img, img_meta=img_meta)
img, img_meta = read_config(self.config.PREPROCESSOR, register.preprocessors, img=img, img_meta=img_meta, is2d= self.config.IS_2D)

print("Preprocessed shape:", img.shape)

Expand Down
2 changes: 1 addition & 1 deletion src/biom3d/config_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __delattr__(self, name): del self[name]
#---------------------------------------------------------------------------
# Auto-config builder-parameters
# PASTE AUTO-CONFIG RESULTS HERE

IS_2D = False
# batch size
BATCH_SIZE = 2

Expand Down
160 changes: 160 additions & 0 deletions src/biom3d/datasets/semseg_batchgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ def centered_crop(img, msk, center, crop_shape, margin=np.zeros(3)):

def located_crop(img, msk, location, crop_shape, margin=np.zeros(3)):
"""Do a crop, forcing the location voxel to be located in the crop.

Parameters
----------
img : ndarray
Image data.
msk : ndarray
Mask data.
location : array_like
Specific voxel location to include in the crop.
crop_shape : array_like
Shape of the crop.
margin : array_like, optional
Margin around the location.

Returns
-------

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indiquer le type de sortie

Cropped image and mask.
"""
img_shape = np.array(img.shape)[1:]
location = np.array(location)
Expand All @@ -96,6 +114,26 @@ def located_crop(img, msk, location, crop_shape, margin=np.zeros(3)):

def foreground_crop(img, msk, final_size, fg_margin, fg=None, use_softmax=True):
"""Do a foreground crop.

Parameters
----------
img : ndarray
Image data.
msk : ndarray
Mask data.
final_size : array_like
Final size of the cropped image and mask.
fg_margin : array_like
Margin around the foreground location.
fg : dict, optional
Foreground information.
use_softmax : bool, optional
If True, assumes softmax activation.

Returns
-------

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indiquer le type de sortie

Cropped image and mask.
"""
if fg is not None:
locations = fg[random.choice(list(fg.keys()))]
Expand All @@ -119,6 +157,20 @@ def foreground_crop(img, msk, final_size, fg_margin, fg=None, use_softmax=True):
def random_crop(img, msk, crop_shape):
"""
randomly crop a portion of size prop of the original image size.

Parameters
----------
img : ndarray
Image data.
msk : ndarray
Mask data.
crop_shape : array_like
Shape of the crop.

Returns
-------

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indiquer le type de sortie

Cropped image and mask.
"""
img_shape = np.array(img.shape)[1:]
assert len(img_shape)==len(crop_shape),"[Error] Not the same dimensions! Image shape {}, Crop shape {}".format(img_shape, crop_shape)
Expand All @@ -135,6 +187,20 @@ def random_crop(img, msk, crop_shape):
def centered_pad(img, final_size, msk=None):
"""
centered pad an img and msk to fit the final_size

Parameters
----------
img : ndarray
Image data.
final_size : array_like
Final size after padding.
msk : ndarray, optional
Mask data.

Returns
-------
tuple or ndarray
Padded image and mask, or only the image if mask is None.
"""
final_size = np.array(final_size)
img_shape = np.array(img.shape[1:])
Expand All @@ -156,6 +222,28 @@ def centered_pad(img, final_size, msk=None):
def random_crop_pad(img, msk, final_size, fg_rate=0.33, fg_margin=np.zeros(3), fg=None, use_softmax=True):
"""
random crop and pad if needed.

Parameters
----------
img : ndarray
Image data.
msk : ndarray
Mask data.
final_size : array_like
Final size after cropping and padding.
fg_rate : float, optional
Probability of focusing the crop on the foreground.
fg_margin : array_like, optional
Margin around the foreground location.
fg : dict, optional
Foreground information.
use_softmax : bool, optional
If True, assumes softmax activation; otherwise sigmoid is used.

Returns
-------

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indiquer le type de sortie

Cropped and padded image and mask.
"""
if type(img)==list: # then batch mode
imgs, msks = [], []
Expand All @@ -179,6 +267,20 @@ def random_crop_pad(img, msk, final_size, fg_rate=0.33, fg_margin=np.zeros(3), f
return img, msk

class RandomCropAndPadTransform(AbstractTransform):
"""
BatchGenerator transform for random cropping and padding.

Parameters
----------
crop_size : array_like
Size of the crop.
fg_rate : float, optional
Probability of focusing the crop on the foreground.
data_key : str, optional
Key for the data in the data dictionary.
label_key : str, optional
Key for the label in the data dictionary.
"""
def __init__(self, crop_size, fg_rate=0.33, data_key="data", label_key="seg"):
self.data_key = data_key
self.label_key = label_key
Expand Down Expand Up @@ -601,6 +703,31 @@ def get_validation_transforms(patch_size: Union[np.ndarray, Tuple[int]],
class BatchGenDataLoader(SlimDataLoaderBase):
"""
Similar as torchio.SubjectsDataset but can be use with an unlimited amount of steps.

Parameters
----------
img_dir : str
Directory containing the images.
msk_dir : str
Directory containing the masks.
batch_size : int
Size of the batches.
nbof_steps : int
Number of steps per epoch.
fg_dir : str, optional
Directory containing foreground information.
folds_csv : str, optional
CSV file containing fold information for dataset splitting.
fold : int, optional
Current fold number for training/validation splitting.
val_split : float, optional
Proportion of data to be used for validation.
train : bool, optional
If True, use the dataset for training; otherwise, use it for validation.
load_data : bool, optional
If True, loads the entire dataset into computer memory.
num_threads_in_mt : int, optional
Number of threads in multi-threaded augmentation.
"""

def __init__(
Expand Down Expand Up @@ -810,6 +937,39 @@ def configure_rotation_dummyDA_mirroring_and_inital_patch_size(patch_size):
return rotation_for_DA, do_dummy_2d_data_aug, initial_patch_size, mirror_axes

class MTBatchGenDataLoader(MultiThreadedAugmenter):
"""
Multi-threaded data loader for efficient data augmentation and loading.

Parameters
----------
img_dir : str
Directory containing the images.
msk_dir : str
Directory containing the masks.
patch_size : array_like
The size of the patches to be extracted.
batch_size : int
Size of the batches.
nbof_steps : int
Number of steps per epoch.
fg_dir : str, optional
Directory containing foreground information.
folds_csv : str, optional
CSV file containing fold information for dataset splitting.
fold : int, optional
Current fold number for training/validation splitting.
val_split : float, optional
Proportion of data to be used for validation.
train : bool, optional
If True, use the dataset for training; otherwise, use it for validation.
load_data : bool, optional
If True, loads the entire dataset into computer memory.
fg_rate : float, optional
Foreground rate for cropping.
num_threads_in_mt : int, optional
Number of threads in multi-threaded augmentation.
"""

def __init__(
self,
img_dir,
Expand Down
Loading