hammerlab / cytokit

Microscopy Image Cytometry Toolkit
Apache License 2.0
115 stars 18 forks source link

Model shape error #31

Closed VasylVaskivskyi closed 4 years ago

VasylVaskivskyi commented 4 years ago

I run the following command

cytokit processor run_all --data-dir /lab/slices/ --config-path experiment.yaml --output-dir /lab/output/

And get these error messages.

Error message

``` 2020-03-24 08:36:40,229:INFO:7361:root: Execution arguments and environment saved to "/lab/output/processor/execution/202003241236.json" 2020-03-24 08:36:58,448:INFO:7361:cytokit.exec.pipeline: Starting Pre-processing pipeline for 2 tasks (2 workers) 2020-03-24 08:36:59,146:INFO:7493:cytokit.exec.pipeline: Loaded tile 201 for region 1 [shape = (1, 1, 4, 1802, 2633)] 2020-03-24 08:36:59,189:INFO:7492:cytokit.exec.pipeline: Loaded tile 1 for region 1 [shape = (1, 1, 4, 1802, 2633)] 2020-03-24 08:36:59,789:INFO:7493:cytokit.exec.pipeline: Loaded tile 202 for region 1 [shape = (1, 1, 4, 1802, 2633)] 2020-03-24 08:36:59,874:INFO:7492:cytokit.exec.pipeline: Loaded tile 2 for region 1 [shape = (1, 1, 4, 1802, 2633)] ``` ``` Using TensorFlow backend. Using TensorFlow backend. distributed.worker - WARNING - Compute Failed Function: run_preprocess_task args: ({'tile_indexes': array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, kwargs: {} Exception: ValueError('A 'Concatenate' layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 462, 668, 512), (None, 462, 669, 256)]',) ``` ``` distributed.worker - WARNING - Compute Failed Function: run_preprocess_task args: ({'tile_indexes': array([200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, kwargs: {} Exception: ValueError('A 'Concatenate' layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 462, 668, 512), (None, 462, 669, 256)]',) ``` ``` Traceback (most recent call last): File "/usr/local/bin/cytokit", line 32, in main() File "/usr/local/bin/cytokit", line 28, in main fire.Fire(Cytokit) File "/opt/conda/envs/cytokit/lib/python3.5/site-packages/fire/core.py", line 127, in Fire component_trace = _Fire(component, args, context, name) File "/opt/conda/envs/cytokit/lib/python3.5/site-packages/fire/core.py", line 366, in _Fire component, remaining_args) File "/opt/conda/envs/cytokit/lib/python3.5/site-packages/fire/core.py", line 542, in _CallCallable result = fn(*varargs, **kwargs) File "/lab/repos/cytokit/python/pipeline/cytokit/cli/__init__.py", line 167, in run_all fn(**{**config[op], **params}) File "/lab/repos/cytokit/python/pipeline/cytokit/cli/processor.py", line 131, in run pipeline.run(pl_config, logging_init_fn=self._logging_init_fn) File "/lab/repos/cytokit/python/pipeline/cytokit/exec/pipeline.py", line 458, in run run_tasks(pl_conf, 'Pre-processing', run_preprocess_task, logging_init_fn) File "/lab/repos/cytokit/python/pipeline/cytokit/exec/pipeline.py", line 421, in run_tasks res = [r.result() for r in res] File "/lab/repos/cytokit/python/pipeline/cytokit/exec/pipeline.py", line 421, in res = [r.result() for r in res] File "/opt/conda/envs/cytokit/lib/python3.5/site-packages/distributed/client.py", line 227, in result six.reraise(*result) File "/opt/conda/envs/cytokit/lib/python3.5/site-packages/six.py", line 702, in reraise raise value.with_traceback(tb) File "/lab/repos/cytokit/python/pipeline/cytokit/exec/pipeline.py", line 441, in run_preprocess_task return run_task(task, ops, preprocess_tile) File "/lab/repos/cytokit/python/pipeline/cytokit/exec/pipeline.py", line 355, in run_task with ops: File "/lab/repos/cytokit/python/pipeline/cytokit/ops/op.py", line 200, in __enter__ v.__enter__() File "/lab/repos/cytokit/python/pipeline/cytokit/ops/op.py", line 152, in __enter__ self.initialize() File "/lab/repos/cytokit/python/pipeline/cytokit/ops/cytometry.py", line 136, in initialize self.cytometer.initialize() File "/lab/repos/cytokit/python/pipeline/cytokit/cytometry/cytometer.py", line 609, in initialize self.model = self._get_model(input_shape) File "/lab/repos/cytokit/python/pipeline/cytokit/cytometry/cytometer.py", line 885, in _get_model return unet_model.get_model(3, input_shape) File "/lab/repos/cytokit/python/pipeline/cytokit/cytometry/models/unet_v2.py", line 82, in get_model [x, y] = get_model_core(n_class, input_shape, **kwargs) File "/lab/repos/cytokit/python/pipeline/cytokit/cytometry/models/unet_v2.py", line 47, in get_model_core y = keras.layers.merge.concatenate([d, c]) File "/opt/conda/envs/cytokit/lib/python3.5/site-packages/keras/layers/merge.py", line 649, in concatenate return Concatenate(axis=axis, **kwargs)(inputs) File "/opt/conda/envs/cytokit/lib/python3.5/site-packages/keras/engine/base_layer.py", line 431, in __call__ self.build(unpack_singleton(input_shapes)) File "/opt/conda/envs/cytokit/lib/python3.5/site-packages/keras/layers/merge.py", line 362, in build 'Got inputs shapes: %s' % (input_shape)) ValueError: A 'Concatenate' layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 462, 668, 512), (None, 462, 669, 256)] ```

At first I thought that there is problem with image dimensions, but I checked them and they are all same. So it seems that there is a mismatch in shapes of model layers.

My experiment.yaml file looks like this

experiment.yaml

``` name: 'VAN0001-RK-1-21' date: '2020-18-03 00:00:00' environment: path_formats: keyence_single_cycle_v01 acquisition: per_cycle_channel_names: [CH1, CH2, CH3, CH4] channel_names: [Synaptopodin, Laminin, DAPI, THP] emission_wavelengths: [461, 519, 568, 666] axial_resolution: 0 # Placeholder, don't know real value. lateral_resolution: 1 # Don't know if this is correct. magnification: 10 num_cycles: 1 num_z_planes: 1 numerical_aperture: 0.45 objective_type: air region_names: [Region1] region_height: 20 region_width: 20 tile_height: 1802 tile_overlap_x: 0 tile_overlap_y: 0 tile_width: 2633 tiling_mode: grid analysis: - aggregate_cytometry_statistics: {mode: best_z_plane} # Uncomment to produce CP exports by default #- cellprofiler_quantification: {export_csv: true, export_db: true, export_db_objects_separately: true} #- cellprofiler_quantification: {export_csv: true, export_db: false} operator: - extract: name: nucleus_boundaries channels: [ cyto_nucleus_boundary ] z: best - montage: { name: segm, extract_name: segm } processor: args: gpus: [ 0, 1 ] run_crop: false run_tile_generator: true run_drift_comp: false run_cytometry: true run_best_focus: true best_focus: {channel: DAPI} drift_compensation: {channel: DAPI} deconvolution: {n_iter: 25, scale_factor: .5} tile_generator: {raw_file_type: keyence_mixed} cytometry: # target_shape dimensions must be evenly divisble by 8 for the U-Net to # work (https://github.com/CellProfiler/CellProfiler-plugins/issues/65). target_shape: [1808, 2640] nuclei_channel_name: DAPI segmentation_params: {memb_min_dist: 8, memb_sigma: 5, memb_gamma: .25, marker_dilation: 3} quantification_params: {nucleus_intensity: true, cell_graph: true} ```

VasylVaskivskyi commented 4 years ago

The problem disappeared when I divided image into tiles of smaller size.