spacr 0.1.63__tar.gz → 0.1.75__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {spacr-0.1.63/spacr.egg-info → spacr-0.1.75}/PKG-INFO +1 -1
- {spacr-0.1.63 → spacr-0.1.75}/setup.py +1 -1
- spacr-0.1.75/spacr/app_annotate.py +53 -0
- spacr-0.1.75/spacr/app_make_masks.py +51 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/core.py +21 -21
- {spacr-0.1.63 → spacr-0.1.75}/spacr/deep_spacr.py +6 -6
- {spacr-0.1.63 → spacr-0.1.75}/spacr/gui.py +4 -20
- {spacr-0.1.63 → spacr-0.1.75}/spacr/gui_core.py +108 -123
- spacr-0.1.63/spacr/app_make_masks.py → spacr-0.1.75/spacr/gui_elements.py +631 -64
- spacr-0.1.75/spacr/gui_utils.py +326 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/gui_wrappers.py +27 -15
- {spacr-0.1.63 → spacr-0.1.75}/spacr/measure.py +4 -4
- {spacr-0.1.63 → spacr-0.1.75}/spacr/settings.py +333 -260
- {spacr-0.1.63 → spacr-0.1.75/spacr.egg-info}/PKG-INFO +1 -1
- spacr-0.1.63/spacr/app_annotate.py +0 -538
- spacr-0.1.63/spacr/gui_elements.py +0 -324
- spacr-0.1.63/spacr/gui_utils.py +0 -139
- {spacr-0.1.63 → spacr-0.1.75}/LICENSE +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/MANIFEST.in +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/README.rst +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/setup.cfg +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/__init__.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/__main__.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/app_classify.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/app_mask.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/app_measure.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/app_sequencing.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/app_umap.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/chris.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/graph_learning.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/gui_run.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/io.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/logger.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/models/cp/toxo_plaque_cyto_e25000_X1120_Y1120.CP_model +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/models/cp/toxo_plaque_cyto_e25000_X1120_Y1120.CP_model_settings.csv +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/models/cp/toxo_pv_lumen.CP_model +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/plot.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/sequencing.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/sim.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/sim_app.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/timelapse.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/utils.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr/version.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr.egg-info/SOURCES.txt +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr.egg-info/dependency_links.txt +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr.egg-info/entry_points.txt +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr.egg-info/requires.txt +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/spacr.egg-info/top_level.txt +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_annotate_app.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_core.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_gui_classify_app.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_gui_mask_app.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_gui_measure_app.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_gui_sim_app.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_gui_utils.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_io.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_mask_app.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_measure.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_plot.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_sim.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_timelapse.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_train.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_umap.py +0 -0
- {spacr-0.1.63 → spacr-0.1.75}/tests/test_utils.py +0 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
import tkinter as tk
|
2
|
+
from .gui import MainApp
|
3
|
+
|
4
|
+
def initiate_annotation_app(parent_frame):
|
5
|
+
from .gui_utils import generate_annotate_fields, annotate_app
|
6
|
+
# Set up the settings window
|
7
|
+
settings_window = tk.Toplevel(parent_frame)
|
8
|
+
settings_window.title("Annotation Settings")
|
9
|
+
settings_window.configure(bg='black') # Set the background color to black
|
10
|
+
|
11
|
+
# Use the existing function to create the settings UI
|
12
|
+
settings_frame = tk.Frame(settings_window, bg='black') # Set the background color to black
|
13
|
+
settings_frame.pack(fill=tk.BOTH, expand=True)
|
14
|
+
vars_dict = generate_annotate_fields(settings_frame)
|
15
|
+
|
16
|
+
def start_annotation_app():
|
17
|
+
settings = {key: data['entry'].get() for key, data in vars_dict.items()}
|
18
|
+
settings['channels'] = settings['channels'].split(',')
|
19
|
+
settings['img_size'] = list(map(int, settings['img_size'].split(','))) # Convert string to list of integers
|
20
|
+
settings['percentiles'] = list(map(int, settings['percentiles'].split(','))) # Convert string to list of integers
|
21
|
+
settings['normalize'] = settings['normalize'].lower() == 'true'
|
22
|
+
settings['rows'] = int(settings['rows'])
|
23
|
+
settings['columns'] = int(settings['columns'])
|
24
|
+
|
25
|
+
try:
|
26
|
+
settings['measurement'] = settings['measurement'].split(',') if settings['measurement'] else None
|
27
|
+
settings['threshold'] = None if settings['threshold'].lower() == 'none' else int(settings['threshold'])
|
28
|
+
except:
|
29
|
+
settings['measurement'] = None
|
30
|
+
settings['threshold'] = None
|
31
|
+
|
32
|
+
settings['db'] = settings.get('db', 'default.db')
|
33
|
+
|
34
|
+
# Convert empty strings to None
|
35
|
+
for key, value in settings.items():
|
36
|
+
if isinstance(value, list):
|
37
|
+
settings[key] = [v if v != '' else None for v in value]
|
38
|
+
elif value == '':
|
39
|
+
settings[key] = None
|
40
|
+
|
41
|
+
settings_window.destroy()
|
42
|
+
annotate_app(parent_frame, settings)
|
43
|
+
|
44
|
+
#start_button = spacrButton(settings_window, text="Start Annotation", command=lambda: start_annotation_app, font=('Helvetica', 12))
|
45
|
+
start_button = tk.Button(settings_window, text="Start Annotation", command=start_annotation_app)
|
46
|
+
start_button.pack(pady=10)
|
47
|
+
|
48
|
+
def start_annotate_app():
|
49
|
+
app = MainApp(default_app="Annotate")
|
50
|
+
app.mainloop()
|
51
|
+
|
52
|
+
if __name__ == "__main__":
|
53
|
+
start_annotate_app()
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import tkinter as tk
|
2
|
+
from tkinter import ttk
|
3
|
+
from .gui import MainApp
|
4
|
+
|
5
|
+
def initiate_make_mask_app(parent_frame):
|
6
|
+
from .gui_elements import modify_masks
|
7
|
+
# Set up the settings window
|
8
|
+
settings_window = tk.Toplevel(parent_frame)
|
9
|
+
settings_window.title("Make Masks Settings")
|
10
|
+
settings_window.configure(bg='black') # Set the background color to black
|
11
|
+
|
12
|
+
# Use the existing function to create the settings UI
|
13
|
+
settings_frame = tk.Frame(settings_window, bg='black') # Set the background color to black
|
14
|
+
settings_frame.pack(fill=tk.BOTH, expand=True)
|
15
|
+
|
16
|
+
vars_dict = {
|
17
|
+
'folder_path': ttk.Entry(settings_frame),
|
18
|
+
'scale_factor': ttk.Entry(settings_frame)
|
19
|
+
}
|
20
|
+
|
21
|
+
# Arrange input fields and labels
|
22
|
+
row = 0
|
23
|
+
for name, entry in vars_dict.items():
|
24
|
+
ttk.Label(settings_frame, text=f"{name.replace('_', ' ').capitalize()}:",
|
25
|
+
background="black", foreground="white").grid(row=row, column=0)
|
26
|
+
entry.grid(row=row, column=1)
|
27
|
+
row += 1
|
28
|
+
|
29
|
+
# Function to be called when "Run" button is clicked
|
30
|
+
def start_make_mask_app():
|
31
|
+
folder_path = vars_dict['folder_path'].get()
|
32
|
+
try:
|
33
|
+
scale_factor = float(vars_dict['scale_factor'].get())
|
34
|
+
except ValueError:
|
35
|
+
scale_factor = None # Handle invalid input gracefully
|
36
|
+
|
37
|
+
# Convert empty strings to None
|
38
|
+
folder_path = folder_path if folder_path != '' else None
|
39
|
+
|
40
|
+
settings_window.destroy()
|
41
|
+
modify_masks(parent_frame, folder_path, scale_factor)
|
42
|
+
|
43
|
+
run_button = tk.Button(settings_window, text="Start Make Masks", command=start_make_mask_app, bg='black', fg='white')
|
44
|
+
run_button.pack(pady=10)
|
45
|
+
|
46
|
+
def start_make_mask_app():
|
47
|
+
app = MainApp(default_app="Make Masks")
|
48
|
+
app.mainloop()
|
49
|
+
|
50
|
+
if __name__ == "__main__":
|
51
|
+
start_make_mask_app()
|
@@ -971,7 +971,7 @@ def generate_dataset(src, file_metadata=None, experiment='TSG101_screen', sample
|
|
971
971
|
shutil.rmtree(temp_dir)
|
972
972
|
print(f"\nSaved {total_images} images to {tar_name}")
|
973
973
|
|
974
|
-
def apply_model_to_tar(tar_path, model_path, file_type='cell_png', image_size=224, batch_size=64, normalize=True, preload='images',
|
974
|
+
def apply_model_to_tar(tar_path, model_path, file_type='cell_png', image_size=224, batch_size=64, normalize=True, preload='images', n_job=10, threshold=0.5, verbose=False):
|
975
975
|
|
976
976
|
from .io import TarImageDataset
|
977
977
|
from .utils import process_vision_results
|
@@ -994,7 +994,7 @@ def apply_model_to_tar(tar_path, model_path, file_type='cell_png', image_size=22
|
|
994
994
|
model = torch.load(model_path)
|
995
995
|
|
996
996
|
dataset = TarImageDataset(tar_path, transform=transform)
|
997
|
-
data_loader = DataLoader(dataset, batch_size=batch_size, shuffle=True,
|
997
|
+
data_loader = DataLoader(dataset, batch_size=batch_size, shuffle=True, n_job=n_job, pin_memory=True)
|
998
998
|
|
999
999
|
model_name = os.path.splitext(os.path.basename(model_path))[0]
|
1000
1000
|
dataset_name = os.path.splitext(os.path.basename(tar_path))[0]
|
@@ -1034,7 +1034,7 @@ def apply_model_to_tar(tar_path, model_path, file_type='cell_png', image_size=22
|
|
1034
1034
|
torch.cuda.memory.empty_cache()
|
1035
1035
|
return df
|
1036
1036
|
|
1037
|
-
def apply_model(src, model_path, image_size=224, batch_size=64, normalize=True,
|
1037
|
+
def apply_model(src, model_path, image_size=224, batch_size=64, normalize=True, n_job=10):
|
1038
1038
|
|
1039
1039
|
from .io import NoClassDataset
|
1040
1040
|
|
@@ -1055,7 +1055,7 @@ def apply_model(src, model_path, image_size=224, batch_size=64, normalize=True,
|
|
1055
1055
|
|
1056
1056
|
print(f'Loading dataset in {src} with {len(src)} images')
|
1057
1057
|
dataset = NoClassDataset(data_dir=src, transform=transform, shuffle=True, load_to_memory=False)
|
1058
|
-
data_loader = DataLoader(dataset, batch_size=batch_size, shuffle=True,
|
1058
|
+
data_loader = DataLoader(dataset, batch_size=batch_size, shuffle=True, n_job=n_job)
|
1059
1059
|
print(f'Loaded {len(src)} images')
|
1060
1060
|
|
1061
1061
|
result_loc = os.path.splitext(model_path)[0]+datetime.date.today().strftime('%y%m%d')+'_'+os.path.splitext(model_path)[1]+'_test_result.csv'
|
@@ -1302,7 +1302,7 @@ def generate_training_dataset(src, mode='annotation', annotation_column='test',
|
|
1302
1302
|
|
1303
1303
|
return
|
1304
1304
|
|
1305
|
-
def generate_loaders(src, train_mode='erm', mode='train', image_size=224, batch_size=32, classes=['nc','pc'],
|
1305
|
+
def generate_loaders(src, train_mode='erm', mode='train', image_size=224, batch_size=32, classes=['nc','pc'], n_job=None, validation_split=0.0, max_show=2, pin_memory=False, normalize=False, channels=[1, 2, 3], augment=False, verbose=False):
|
1306
1306
|
|
1307
1307
|
"""
|
1308
1308
|
Generate data loaders for training and validation/test datasets.
|
@@ -1314,7 +1314,7 @@ def generate_loaders(src, train_mode='erm', mode='train', image_size=224, batch_
|
|
1314
1314
|
- image_size (int): The size of the input images.
|
1315
1315
|
- batch_size (int): The batch size for the data loaders.
|
1316
1316
|
- classes (list): The list of classes to consider.
|
1317
|
-
-
|
1317
|
+
- n_job (int): The number of worker threads for data loading.
|
1318
1318
|
- validation_split (float): The fraction of data to use for validation when train_mode is 'erm'.
|
1319
1319
|
- max_show (int): The maximum number of images to show when verbose is True.
|
1320
1320
|
- pin_memory (bool): Whether to pin memory for faster data transfer.
|
@@ -1404,10 +1404,10 @@ def generate_loaders(src, train_mode='erm', mode='train', image_size=224, batch_
|
|
1404
1404
|
#val_dataset = augment_dataset(val_dataset, is_grayscale=(len(channels) == 1))
|
1405
1405
|
print(f'Data after augmentation: Train: {len(train_dataset)}')#, Validataion:{len(val_dataset)}')
|
1406
1406
|
|
1407
|
-
train_loaders = DataLoader(train_dataset, batch_size=batch_size, shuffle=shuffle,
|
1408
|
-
val_loaders = DataLoader(val_dataset, batch_size=batch_size, shuffle=shuffle,
|
1407
|
+
train_loaders = DataLoader(train_dataset, batch_size=batch_size, shuffle=shuffle, n_job=n_job if n_job is not None else 0, pin_memory=pin_memory)
|
1408
|
+
val_loaders = DataLoader(val_dataset, batch_size=batch_size, shuffle=shuffle, n_job=n_job if n_job is not None else 0, pin_memory=pin_memory)
|
1409
1409
|
else:
|
1410
|
-
train_loaders = DataLoader(data, batch_size=batch_size, shuffle=shuffle,
|
1410
|
+
train_loaders = DataLoader(data, batch_size=batch_size, shuffle=shuffle, n_job=n_job if n_job is not None else 0, pin_memory=pin_memory)
|
1411
1411
|
|
1412
1412
|
elif train_mode == 'irm':
|
1413
1413
|
data = MyDataset(data_dir, classes, transform=transform, shuffle=shuffle, pin_memory=pin_memory)
|
@@ -1436,13 +1436,13 @@ def generate_loaders(src, train_mode='erm', mode='train', image_size=224, batch_
|
|
1436
1436
|
#val_dataset = augment_dataset(val_dataset, is_grayscale=(len(channels) == 1))
|
1437
1437
|
print(f'Data after augmentation: Train: {len(train_dataset)}')#, Validataion:{len(val_dataset)}')
|
1438
1438
|
|
1439
|
-
train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=shuffle,
|
1440
|
-
val_loader = DataLoader(val_dataset, batch_size=batch_size, shuffle=shuffle,
|
1439
|
+
train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=shuffle, n_job=n_job if n_job is not None else 0, pin_memory=pin_memory)
|
1440
|
+
val_loader = DataLoader(val_dataset, batch_size=batch_size, shuffle=shuffle, n_job=n_job if n_job is not None else 0, pin_memory=pin_memory)
|
1441
1441
|
|
1442
1442
|
train_loaders.append(train_loader)
|
1443
1443
|
val_loaders.append(val_loader)
|
1444
1444
|
else:
|
1445
|
-
train_loader = DataLoader(plate_data, batch_size=batch_size, shuffle=shuffle,
|
1445
|
+
train_loader = DataLoader(plate_data, batch_size=batch_size, shuffle=shuffle, n_job=n_job if n_job is not None else 0, pin_memory=pin_memory)
|
1446
1446
|
train_loaders.append(train_loader)
|
1447
1447
|
val_loaders.append(None)
|
1448
1448
|
|
@@ -2078,11 +2078,11 @@ def identify_masks(src, object_type, model_name, batch_size, channels, diameter,
|
|
2078
2078
|
else:
|
2079
2079
|
radius = 100
|
2080
2080
|
|
2081
|
-
|
2082
|
-
if
|
2083
|
-
|
2081
|
+
n_job = os.cpu_count()-2
|
2082
|
+
if n_job < 1:
|
2083
|
+
n_job = 1
|
2084
2084
|
|
2085
|
-
mask_stack = _btrack_track_cells(src, name, batch_filenames, object_type, plot, save, masks_3D=masks, mode=timelapse_mode, timelapse_remove_transient=timelapse_remove_transient, radius=radius,
|
2085
|
+
mask_stack = _btrack_track_cells(src, name, batch_filenames, object_type, plot, save, masks_3D=masks, mode=timelapse_mode, timelapse_remove_transient=timelapse_remove_transient, radius=radius, n_job=n_job)
|
2086
2086
|
if timelapse_mode == 'trackpy':
|
2087
2087
|
mask_stack = _trackpy_track_cells(src, name, batch_filenames, object_type, masks, timelapse_displacement, timelapse_memory, timelapse_remove_transient, plot, save, timelapse_mode)
|
2088
2088
|
|
@@ -2303,9 +2303,9 @@ def generate_cellpose_masks(src, settings, object_type):
|
|
2303
2303
|
else:
|
2304
2304
|
radius = 100
|
2305
2305
|
|
2306
|
-
|
2307
|
-
if
|
2308
|
-
|
2306
|
+
n_job = os.cpu_count()-2
|
2307
|
+
if n_job < 1:
|
2308
|
+
n_job = 1
|
2309
2309
|
|
2310
2310
|
mask_stack = _btrack_track_cells(src=src,
|
2311
2311
|
name=name,
|
@@ -2317,7 +2317,7 @@ def generate_cellpose_masks(src, settings, object_type):
|
|
2317
2317
|
mode=timelapse_mode,
|
2318
2318
|
timelapse_remove_transient=timelapse_remove_transient,
|
2319
2319
|
radius=radius,
|
2320
|
-
|
2320
|
+
n_job=n_job)
|
2321
2321
|
if timelapse_mode == 'trackpy':
|
2322
2322
|
mask_stack = _trackpy_track_cells(src=src,
|
2323
2323
|
name=name,
|
@@ -2551,7 +2551,7 @@ def compare_cellpose_masks(src, verbose=False, processes=None, save=True):
|
|
2551
2551
|
common_files.intersection_update(os.listdir(d))
|
2552
2552
|
common_files = list(common_files)
|
2553
2553
|
|
2554
|
-
# Create a pool of
|
2554
|
+
# Create a pool of n_job
|
2555
2555
|
with Pool(processes=processes) as pool:
|
2556
2556
|
args = [(src, filename, dirs, conditions) for filename in common_files]
|
2557
2557
|
results = pool.map(compare_mask, args)
|
@@ -230,7 +230,7 @@ def train_test_model(src, settings, custom_model=False, custom_model_path=None):
|
|
230
230
|
image_size=settings['image_size'],
|
231
231
|
batch_size=settings['batch_size'],
|
232
232
|
classes=settings['classes'],
|
233
|
-
|
233
|
+
n_job=settings['n_job'],
|
234
234
|
validation_split=settings['val_split'],
|
235
235
|
pin_memory=settings['pin_memory'],
|
236
236
|
normalize=settings['normalize'],
|
@@ -255,7 +255,7 @@ def train_test_model(src, settings, custom_model=False, custom_model_path=None):
|
|
255
255
|
optimizer_type = settings['optimizer_type'],
|
256
256
|
use_checkpoint = settings['use_checkpoint'],
|
257
257
|
dropout_rate = settings['dropout_rate'],
|
258
|
-
|
258
|
+
n_job = settings['n_job'],
|
259
259
|
val_loaders = val,
|
260
260
|
test_loaders = None,
|
261
261
|
intermedeate_save = settings['intermedeate_save'],
|
@@ -276,7 +276,7 @@ def train_test_model(src, settings, custom_model=False, custom_model_path=None):
|
|
276
276
|
image_size=settings['image_size'],
|
277
277
|
batch_size=settings['batch_size'],
|
278
278
|
classes=settings['classes'],
|
279
|
-
|
279
|
+
n_job=settings['n_job'],
|
280
280
|
validation_split=0.0,
|
281
281
|
pin_memory=settings['pin_memory'],
|
282
282
|
normalize=settings['normalize'],
|
@@ -315,7 +315,7 @@ def train_test_model(src, settings, custom_model=False, custom_model_path=None):
|
|
315
315
|
torch.cuda.memory.empty_cache()
|
316
316
|
gc.collect()
|
317
317
|
|
318
|
-
def train_model(dst, model_type, train_loaders, train_loader_names, train_mode='erm', epochs=100, learning_rate=0.0001, weight_decay=0.05, amsgrad=False, optimizer_type='adamw', use_checkpoint=False, dropout_rate=0,
|
318
|
+
def train_model(dst, model_type, train_loaders, train_loader_names, train_mode='erm', epochs=100, learning_rate=0.0001, weight_decay=0.05, amsgrad=False, optimizer_type='adamw', use_checkpoint=False, dropout_rate=0, n_job=20, val_loaders=None, test_loaders=None, init_weights='imagenet', intermedeate_save=None, chan_dict=None, schedule = None, loss_type='binary_cross_entropy_with_logits', gradient_accumulation=False, gradient_accumulation_steps=4, channels=['r','g','b']):
|
319
319
|
"""
|
320
320
|
Trains a model using the specified parameters.
|
321
321
|
|
@@ -332,7 +332,7 @@ def train_model(dst, model_type, train_loaders, train_loader_names, train_mode='
|
|
332
332
|
optimizer_type (str, optional): The type of optimizer to use. Defaults to 'adamw'.
|
333
333
|
use_checkpoint (bool, optional): Whether to use checkpointing during training. Defaults to False.
|
334
334
|
dropout_rate (float, optional): The dropout rate for the model. Defaults to 0.
|
335
|
-
|
335
|
+
n_job (int, optional): The number of n_job for data loading. Defaults to 20.
|
336
336
|
val_loaders (list, optional): A list of validation data loaders. Defaults to None.
|
337
337
|
test_loaders (list, optional): A list of test data loaders. Defaults to None.
|
338
338
|
init_weights (str, optional): The initialization weights for the model. Defaults to 'imagenet'.
|
@@ -357,7 +357,7 @@ def train_model(dst, model_type, train_loaders, train_loader_names, train_mode='
|
|
357
357
|
|
358
358
|
use_cuda = torch.cuda.is_available()
|
359
359
|
device = torch.device("cuda" if use_cuda else "cpu")
|
360
|
-
kwargs = {'
|
360
|
+
kwargs = {'n_job': n_job, 'pin_memory': True} if use_cuda else {}
|
361
361
|
|
362
362
|
for idx, (images, labels, filenames) in enumerate(train_loaders):
|
363
363
|
batch, chans, height, width = images.shape
|
@@ -5,8 +5,6 @@ import os, requests
|
|
5
5
|
from multiprocessing import set_start_method
|
6
6
|
from .gui_elements import spacrButton, create_menu_bar, set_dark_style
|
7
7
|
from .gui_core import initiate_root
|
8
|
-
from .app_annotate import initiate_annotation_app_root
|
9
|
-
from .app_make_masks import initiate_mask_app_root
|
10
8
|
|
11
9
|
class MainApp(tk.Tk):
|
12
10
|
def __init__(self, default_app=None):
|
@@ -22,8 +20,8 @@ class MainApp(tk.Tk):
|
|
22
20
|
self.gui_apps = {
|
23
21
|
"Mask": (lambda frame: initiate_root(frame, 'mask'), "Generate cellpose masks for cells, nuclei and pathogen images."),
|
24
22
|
"Measure": (lambda frame: initiate_root(frame, 'measure'), "Measure single object intensity and morphological feature. Crop and save single object image"),
|
25
|
-
"Annotate": (
|
26
|
-
"Make Masks": (
|
23
|
+
"Annotate": (lambda frame: initiate_root(frame, 'annotate'), "Annotation single object images on a grid. Annotations are saved to database."),
|
24
|
+
"Make Masks": (lambda frame: initiate_root(frame, 'make_masks'),"Adjust pre-existing Cellpose models to your specific dataset for improved performance"),
|
27
25
|
"Classify": (lambda frame: initiate_root(frame, 'classify'), "Train Torch Convolutional Neural Networks (CNNs) or Transformers to classify single object images."),
|
28
26
|
"Sequencing": (lambda frame: initiate_root(frame, 'sequencing'), "Analyze sequensing data."),
|
29
27
|
"Umap": (lambda frame: initiate_root(frame, 'umap'), "Generate UMAP embedings with datapoints represented as images.")
|
@@ -32,21 +30,8 @@ class MainApp(tk.Tk):
|
|
32
30
|
self.selected_app = tk.StringVar()
|
33
31
|
self.create_widgets()
|
34
32
|
|
35
|
-
|
36
|
-
if default_app == "Mask":
|
33
|
+
if default_app in self.gui_apps:
|
37
34
|
self.load_app(default_app, self.gui_apps[default_app][0])
|
38
|
-
elif default_app == "Measure":
|
39
|
-
self.load_app(default_app, self.gui_apps[default_app][1])
|
40
|
-
elif default_app == "Annotate":
|
41
|
-
self.load_app(default_app, self.gui_apps[default_app][2])
|
42
|
-
elif default_app == "Make Masks":
|
43
|
-
self.load_app(default_app, self.gui_apps[default_app][3])
|
44
|
-
elif default_app == "Classify":
|
45
|
-
self.load_app(default_app, self.gui_apps[default_app][4])
|
46
|
-
elif default_app == "Sequencing":
|
47
|
-
self.load_app(default_app, self.gui_apps[default_app][5])
|
48
|
-
elif default_app == "Umap":
|
49
|
-
self.load_app(default_app, self.gui_apps[default_app][6])
|
50
35
|
|
51
36
|
def create_widgets(self):
|
52
37
|
# Create the menu bar
|
@@ -88,7 +73,6 @@ class MainApp(tk.Tk):
|
|
88
73
|
|
89
74
|
# Create custom button with text
|
90
75
|
button = spacrButton(buttons_frame, text=app_name, command=lambda app_name=app_name, app_func=app_func: self.load_app(app_name, app_func), font=('Helvetica', 12))
|
91
|
-
#button = ttk.Button(buttons_frame, text=app_name, command=lambda app_name=app_name, app_func=app_func: self.load_app(app_name, app_func), style='Custom.TButton')
|
92
76
|
button.grid(row=i, column=0, pady=10, padx=10, sticky="w")
|
93
77
|
|
94
78
|
description_label = tk.Label(buttons_frame, text=app_desc, bg="black", fg="white", wraplength=800, justify="left", font=('Helvetica', 12))
|
@@ -161,4 +145,4 @@ def gui_app():
|
|
161
145
|
|
162
146
|
if __name__ == "__main__":
|
163
147
|
set_start_method('spawn', force=True)
|
164
|
-
gui_app()
|
148
|
+
gui_app()
|