|
| 1 | +import tensorflow as tf |
| 2 | +import tensorflow_datasets as tfds |
| 3 | + |
| 4 | +import numpy as np |
| 5 | +import pandas as pd |
| 6 | + |
| 7 | +_DESCRIPTION = """ |
| 8 | +This dataset includes tracking data from DIC-C2DH-HELA (provided by the sixth edition of the Cell Tracking Challenge). |
| 9 | +It consists of two dataframes: ``nodes`` and ``parenthood``. ``nodes`` contains information about the individual |
| 10 | +cells, while "parenthood" includes information on the lineage of the cells. |
| 11 | +""" |
| 12 | + |
| 13 | +_CITATION = """ |
| 14 | +@article{pineda2022geometric, |
| 15 | + title={Geometric deep learning reveals the spatiotemporal fingerprint of microscopic motion}, |
| 16 | + author={Pineda, Jes{\'u}s and Midtvedt, Benjamin and Bachimanchi, Harshith and No{\'e}, Sergio and Midtvedt, Daniel and Volpe, Giovanni and Manzo, Carlo}, |
| 17 | + journal={arXiv preprint arXiv:2202.06355}, |
| 18 | + year={2022} |
| 19 | +} |
| 20 | +""" |
| 21 | + |
| 22 | + |
| 23 | +class DetectionLinkingHela(tfds.core.GeneratorBasedBuilder): |
| 24 | + """DatasetBuilder for detection_linking_Hela dataset.""" |
| 25 | + |
| 26 | + VERSION = tfds.core.Version("1.0.0") |
| 27 | + RELEASE_NOTES = { |
| 28 | + "1.0.0": "Initial release.", |
| 29 | + } |
| 30 | + |
| 31 | + def _info(self) -> tfds.core.DatasetInfo: |
| 32 | + """Returns the dataset metadata.""" |
| 33 | + NODE_FEATURES = self.get_node_features() |
| 34 | + return tfds.core.DatasetInfo( |
| 35 | + builder=self, |
| 36 | + description=_DESCRIPTION, |
| 37 | + features=tfds.features.FeaturesDict( |
| 38 | + { |
| 39 | + "nodes": tfds.features.FeaturesDict( |
| 40 | + { |
| 41 | + **{ |
| 42 | + key: tfds.features.Tensor( |
| 43 | + shape=(None,), dtype=NODE_FEATURES[key] |
| 44 | + ) |
| 45 | + for key in NODE_FEATURES.keys() |
| 46 | + }, |
| 47 | + } |
| 48 | + ), |
| 49 | + "parenthood": tfds.features.FeaturesDict( |
| 50 | + { |
| 51 | + "child": tfds.features.Tensor( |
| 52 | + shape=(None,), dtype=tf.int32 |
| 53 | + ), |
| 54 | + "parent": tfds.features.Tensor( |
| 55 | + shape=(None,), dtype=tf.int32 |
| 56 | + ), |
| 57 | + } |
| 58 | + ), |
| 59 | + "images": tfds.features.Tensor( |
| 60 | + shape=(84, 512, 512, 1), dtype=tf.float64 |
| 61 | + ), |
| 62 | + "masks": tfds.features.Tensor( |
| 63 | + shape=(84, 512, 512, 1), dtype=tf.float64 |
| 64 | + ), |
| 65 | + } |
| 66 | + ), |
| 67 | + supervised_keys=None, |
| 68 | + homepage="https://dataset-homepage/", |
| 69 | + citation=_CITATION, |
| 70 | + ) |
| 71 | + |
| 72 | + def _split_generators(self, dl_manager: tfds.download.DownloadManager): |
| 73 | + """Returns SplitGenerators.""" |
| 74 | + # Downloads the data and defines the splits |
| 75 | + path = dl_manager.download_and_extract( |
| 76 | + "https://drive.google.com/u/1/uc?id=1itHz4KmrUqDCKpGNyHUiHE4AFhwiJ5XR&export=download" |
| 77 | + ) |
| 78 | + |
| 79 | + # Returns the Dict[split names, Iterator[Key, Example]] |
| 80 | + return { |
| 81 | + "train": self._generate_examples( |
| 82 | + path / "detection_linking_hela", "train" |
| 83 | + ), |
| 84 | + "test": self._generate_examples( |
| 85 | + path / "detection_linking_hela", "test" |
| 86 | + ), |
| 87 | + } |
| 88 | + |
| 89 | + def _generate_examples(self, path, split): |
| 90 | + """Yields examples.""" |
| 91 | + |
| 92 | + # Load data |
| 93 | + nodes, parenthood, images, masks = ( |
| 94 | + pd.read_csv(path / split / "nodesdf.csv"), |
| 95 | + pd.read_csv(path / split / "parenthood.csv"), |
| 96 | + np.load(path / split / "images.npy"), |
| 97 | + np.load(path / split / "masks.npy"), |
| 98 | + ) |
| 99 | + |
| 100 | + yield "_", { |
| 101 | + "nodes": {**nodes.to_dict("list")}, |
| 102 | + "parenthood": {**parenthood.to_dict("list")}, |
| 103 | + "images": images * 1.0, |
| 104 | + "masks": masks * 1.0, |
| 105 | + } |
| 106 | + |
| 107 | + def get_node_features(self): |
| 108 | + return { |
| 109 | + "frame": tf.int32, |
| 110 | + "label": tf.int32, |
| 111 | + "centroid-0": tf.float32, |
| 112 | + "centroid-1": tf.float32, |
| 113 | + "area": tf.float32, |
| 114 | + "mean_intensity": tf.float32, |
| 115 | + "perimeter": tf.float32, |
| 116 | + "eccentricity": tf.float32, |
| 117 | + "solidity": tf.float32, |
| 118 | + "set": tf.float32, |
| 119 | + "parent": tf.int32, |
| 120 | + "solution": tf.float32, |
| 121 | + } |
0 commit comments