Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
guijacquemet authored Apr 29, 2024
1 parent 87f77f7 commit 89fc178
Showing 1 changed file with 22 additions and 34 deletions.
56 changes: 22 additions & 34 deletions Colab_notebooks/Cellpose_2D_ZeroCostDL4Mic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"source": [
"#@markdown ##Load key dependencies\n",
"\n",
"Notebook_version = '1.16.2'\n",
"Notebook_version = '1.16.3'\n",
"Network = 'Cellpose'\n",
"\n",
"from builtins import any as b_any\n",
Expand Down Expand Up @@ -926,7 +926,7 @@
"source": [
"#Data augmentation\n",
"\n",
"Use_Data_augmentation = True #@param {type:\"boolean\"}\n",
"Use_Data_augmentation = False #@param {type:\"boolean\"}\n",
"\n",
"if Use_Data_augmentation:\n",
" print(bcolors.WARNING+\"Data augmentation enabled\")\n",
Expand Down Expand Up @@ -970,9 +970,9 @@
"source": [
"# @markdown ##Loading weights from a pre-trained network\n",
"\n",
"Use_pretrained_model = False #@param {type:\"boolean\"}\n",
"Use_pretrained_model = True #@param {type:\"boolean\"}\n",
"\n",
"Pretrained_model = \"Cytoplasm\" #@param [\"Cytoplasm\",\"Cytoplasm2\", \"Nuclei\", \"LiveCell\", \"TissueNet\", \"Own_model\"]\n",
"Pretrained_model = \"Cytoplasm3\" #@param [\"Cytoplasm\",\"Cytoplasm2\", \"Cytoplasm3\", \"Nuclei\", \"LiveCell\", \"TissueNet\", \"Own_model\"]\n",
"\n",
"#@markdown ###If using your own model, please provide the path to the model (not the folder):\n",
"pretrained_model_path = \"\" #@param {type:\"string\"}\n",
Expand All @@ -995,6 +995,10 @@
" model_to_load = \"cyto2\"\n",
" print('The model Cytoplasm2 (cyto2) will be used as a starting point')\n",
"\n",
" if Pretrained_model == \"Cytoplasm3\":\n",
" model_to_load = \"cyto3\"\n",
" print('The model Cytoplasm3 (cyto3) will be used as a starting point')\n",
"\n",
" if Pretrained_model == \"Nuclei\":\n",
" model_to_load = \"nuclei\"\n",
" print('The model nuclei will be used as a starting point')\n",
Expand Down Expand Up @@ -1117,37 +1121,12 @@
"start = time.time()\n",
"\n",
"if not Use_Data_augmentation:\n",
" !python -m cellpose --train --use_gpu --fast_mode --dir \"$train_folder\" --test_dir \"$test_folder\" --pretrained_model $model_to_load --chan $Training_channel --chan2 $Second_training_channel --n_epochs $number_of_epochs --learning_rate $initial_learning_rate --batch_size $batch_size --img_filter img --mask_filter masks --verbose\n",
" !python -m cellpose --train --use_gpu --dir \"$train_folder\" --test_dir \"$test_folder\" --pretrained_model $model_to_load --chan $Training_channel --chan2 $Second_training_channel --n_epochs $number_of_epochs --learning_rate $initial_learning_rate --batch_size $batch_size --img_filter img --mask_filter masks --verbose\n",
"\n",
"else:\n",
" !python -m cellpose --train --use_gpu --fast_mode --dir \"$train_folder\" --test_dir \"$test_folder\" --pretrained_model $model_to_load --chan $Training_channel --chan2 $Second_training_channel --n_epochs $number_of_epochs --learning_rate $initial_learning_rate --batch_size $batch_size --img_filter img --mask_filter masks --verbose\n",
"\n",
"\n",
"#Settings\n",
"# --check_mkl', action='store_true', help='check if mkl working'\n",
" !python -m cellpose --train --use_gpu --dir \"$train_folder\" --test_dir \"$test_folder\" --pretrained_model $model_to_load --chan $Training_channel --chan2 $Second_training_channel --n_epochs $number_of_epochs --learning_rate $initial_learning_rate --batch_size $batch_size --img_filter img --mask_filter masks --verbose\n",
"\n",
"#'--mkldnn', action='store_true', help='for mxnet, force MXNET_SUBGRAPH_BACKEND = \"MKLDNN\"')\n",
"\n",
"#'--train', action='store_true', help='train network using images in dir')\n",
"#'--dir', required=False, help='folder containing data to run or train on')\n",
"# '--mxnet', action='store_true', help='use mxnet')\n",
"# '--img_filter', required=False, default=[], type=str, help='end string for images to run on')\n",
"# '--use_gpu', action='store_true', help='use gpu if mxnet with cuda installed')\n",
"# '--fast_mode', action='store_true', help=\"make code run faster by turning off 4 network averaging\")\n",
"# '--resample', action='store_true', help=\"run dynamics on full image (slower for images with large diameters)\")\n",
"# '--no_interp', action='store_true', help='do not interpolate when running dynamics (was default)')\n",
"# '--do_3D', action='store_true', help='process images as 3D stacks of images (nplanes x nchan x Ly x Lx')\n",
"\n",
"# settings for training\n",
"# parser.add_argument('--train_size', action='store_true', help='train size network at end of training')\n",
"# parser.add_argument('--mask_filter', required=False, default='_masks', type=str, help='end string for masks to run on')\n",
"# parser.add_argument('--test_dir', required=False, default=[], type=str, help='folder containing test data (optional)')\n",
"# parser.add_argument('--learning_rate', required=False, default=0.2, type=float, help='learning rate')\n",
"# parser.add_argument('--n_epochs', required=False, default=500, type=int, help='number of epochs')\n",
"# parser.add_argument('--batch_size', required=False, default=8, type=int, help='batch size')\n",
"# parser.add_argument('--residual_on', required=False, default=1, type=int, help='use residual connections')\n",
"# parser.add_argument('--style_on', required=False, default=1, type=int, help='use style vector')\n",
"# parser.add_argument('--concatenation', required=False, dfault=0, type=int, help='concatenate downsampled layers with upsampled layers (off by default which means they are added)')\n",
"\n",
"\n",
"\n",
Expand Down Expand Up @@ -1187,7 +1166,7 @@
"<font size = 4>**`model_choice`:** Choose the model to use to make predictions. This model needs to be a Cellpose model. You can also use the pretrained models already available in cellpose:\n",
"\n",
"- The cytoplasm model in cellpose is trained on two-channel images, where the first channel is the channel to segment, and the second channel is an optional nuclear channel.\n",
"- The cytoplasm2 model is an updated cytoplasm model trained with user-submitted images.\n",
"- The cytoplasm2 and 3 models are updated cytoplasm model trained with user-submitted images.\n",
"\n",
"- The Nuclei model in cellpose is trained on two-channel images, where the first channel is the channel to segment, and the second channel is always set to an array of zeros.\n",
"\n",
Expand Down Expand Up @@ -1217,7 +1196,7 @@
"\n",
"#@markdown ###If not, indicate which model you want to assess:\n",
"\n",
"QC_model = \"Own_model\" #@param [\"Cytoplasm\",\"Cytoplasm2\",\"LiveCell\", \"TissueNet\", \"Cytoplasm2_Omnipose\", \"Bacteria_Omnipose\", \"Nuclei\", \"Own_model\"]\n",
"QC_model = \"Own_model\" #@param [\"Cytoplasm\",\"Cytoplasm2\", \"Cytoplasm3\", \"LiveCell\", \"TissueNet\", \"Cytoplasm2_Omnipose\", \"Bacteria_Omnipose\", \"Nuclei\", \"Own_model\"]\n",
"\n",
"#@markdown ###If using your own model, please provide the path to the model (not the folder):\n",
"\n",
Expand Down Expand Up @@ -1258,7 +1237,12 @@
" QC_model_folder = Saving_path\n",
" QC_model_name = \"Cytoplasm2\"\n",
"\n",
" print('The model \"Cytoplasm\" will be evaluated')\n",
" print('The model \"Cytoplasm2\" will be evaluated')\n",
"\n",
" if model_choice == \"Cytoplasm3\":\n",
" channels=[segment_channel,nuclear_channel]\n",
" model = models.Cellpose(gpu=True, model_type=\"cyto3\")\n",
" print(\"Cytoplasm 3 model enabled\")\n",
"\n",
" if QC_model == \"Cytoplasm2_Omnipose\":\n",
" model = models.Cellpose(gpu=True, model_type=\"cyto2_omni\")\n",
Expand Down Expand Up @@ -2510,6 +2494,10 @@
"source": [
"# **7. Version log**\n",
"---\n",
"<font size = 4>**v1.16.3**:\n",
"* Cyto3 added\n",
"* --fast mode removed\n",
"\n",
"<font size = 4>**v1.16.2**:\n",
"* Debug in load a model or run QC with the current model (list of files avoids pdf and QC_model is checked rather than the model type)\n",
"\n",
Expand Down

0 comments on commit 89fc178

Please sign in to comment.