YuxuanZhang888 commited on
Commit
3cda685
·
verified ·
1 Parent(s): 2ec2532

Updated the 'example' and 'full_data' configuration.

Browse files
Files changed (1) hide show
  1. ColonCancerCTDatasetScript.py +30 -43
ColonCancerCTDatasetScript.py CHANGED
@@ -8,46 +8,29 @@ import re
8
  import s3fs
9
  import random
10
 
11
- manifest_url = "https://drive.google.com/uc?id=1JBkQTXeieyN9_6BGdTF_DDlFFyZrGyU6"
12
- manifest_file = gdown.download(manifest_url, 'manifest_file.s5cmd', quiet=False)
 
 
13
  fs = s3fs.S3FileSystem(anon=True)
14
 
15
- _DESCRIPTION = """
16
- This dataset, curated from the comprehensive collection by the National Cancer Institute (NCI)
17
- and hosted on AWS, contains over 900,000 colon CT images, along with the corresponding patients'
18
- information. It is designed to help researcher in developing advanced machine learning models
19
- for in-depth studies in colon cancer.
20
- """
21
  _HOMEPAGE = "https://imaging.datacommons.cancer.gov/"
22
  _LICENSE = "https://fairsharing.org/FAIRsharing.0b5a1d"
23
- _CITATION = """\
24
- @article{fedorov2021nci,
25
- title={NCI imaging data commons},
26
- author={Fedorov, Andrey and Longabaugh, William JR and Pot, David
27
- and Clunie, David A and Pieper, Steve and Aerts, Hugo JWL and
28
- Homeyer, Andr{\'e} and Lewis, Rob and Akbarzadeh, Afshin and
29
- Bontempi, Dennis and others},
30
- journal={Cancer research},
31
- volume={81},
32
- number={16},
33
- pages={4188--4193},
34
- year={2021},
35
- publisher={AACR}
36
- }
37
- """
38
 
39
  class ColonCancerCTDataset(datasets.GeneratorBasedBuilder):
40
- """This dataset script retrieves the dataset using a manifest file from the original dataset's
41
- homepage. The file lists the S3 paths for each series of CT images and metadata, guiding the download
42
- from AWS. After processing the original content, this dataset will contian the image of the colonography,
43
- image type, study date, series date, manufacturer details, study descriptions, series descriptions,
44
- and patient demographics including sex, age, and pregnancy status.
45
- """
46
  VERSION = datasets.Version("1.1.0")
47
 
 
 
 
 
 
 
48
  def _info(self):
49
- """Returns DatasetInfo."""
50
- # This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
51
  return datasets.DatasetInfo(
52
  description=_DESCRIPTION,
53
  features=datasets.Features(
@@ -67,24 +50,29 @@ class ColonCancerCTDataset(datasets.GeneratorBasedBuilder):
67
  homepage = _HOMEPAGE,
68
  license = _LICENSE,
69
  citation = _CITATION
70
- )
 
71
 
72
  def _split_generators(self, dl_manager):
73
- """Returns a list of SplitGenerators."""
74
- # This method is tasked with extracting the S3 paths of the data and defining the splits
75
- # by shuffling and randomly partitioning the paths in the manifest file.
76
  s3_series_paths = []
77
  s3_individual_paths = []
 
 
 
 
 
78
  with open(manifest_file, 'r') as file:
79
- for line in file:
80
- match = re.search(r'cp (s3://[\S]+) .', line)
81
- if match:
82
- s3_series_paths.append(match.group(1)[:-2]) # Deleting the '/*' in directories
83
  for series in s3_series_paths:
84
  for content in fs.ls(series):
85
- s3_individual_paths.append(fs.info(content)['Key']) # Retrieve the individual DICOM file's S3 path
86
 
87
- random.shuffle(s3_individual_paths) # Randomly shuffles the paths for partitioning
88
 
89
  # Define the split sizes
90
  train_size = int(0.7 * len(s3_individual_paths))
@@ -120,13 +108,12 @@ class ColonCancerCTDataset(datasets.GeneratorBasedBuilder):
120
 
121
  def _generate_examples(self, paths, split):
122
  """Yields examples."""
123
- # This method will yield examples, i.e. rows in the dataset.
124
  for path in paths:
125
  key = path
126
  with fs.open(path, 'rb') as f:
127
  dicom_data = pydicom.dcmread(f)
128
  pixel_array = dicom_data.pixel_array
129
- # Converting pixel array into PNG image
130
  # Adjust for MONOCHROME1 to invert the grayscale values
131
  if dicom_data.PhotometricInterpretation == "MONOCHROME1":
132
  pixel_array = np.max(pixel_array) - pixel_array
 
8
  import s3fs
9
  import random
10
 
11
+ example_manifest_url = "https://drive.google.com/uc?id=1JBkQTXeieyN9_6BGdTF_DDlFFyZrGyU6"
12
+ example_manifest_file = gdown.download(example_manifest_url, 'manifest_file.s5cmd', quiet = False)
13
+ full_manifest_url = "https://drive.google.com/uc?id=1KP6qxcQoPF4MJdEPNwW7J6BlL_sUJ17j"
14
+ full_manifest_file = gdown.download(full_manifest_url, 'full_manifest_file.s5cmd', quiet = False)
15
  fs = s3fs.S3FileSystem(anon=True)
16
 
17
+ _DESCRIPTION = "This is the description"
 
 
 
 
 
18
  _HOMEPAGE = "https://imaging.datacommons.cancer.gov/"
19
  _LICENSE = "https://fairsharing.org/FAIRsharing.0b5a1d"
20
+ _CITATION = "National Cancer Institute Imaging Data Commons (IDC) Collections was accessed on DATE from https://registry.opendata.aws/nci-imaging-data-commons"
21
+
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  class ColonCancerCTDataset(datasets.GeneratorBasedBuilder):
24
+ """TODO: Short description of my dataset."""
 
 
 
 
 
25
  VERSION = datasets.Version("1.1.0")
26
 
27
+ BUILDER_CONFIGS = [
28
+ datasets.BuilderConfig(name="example", version=VERSION, description="This is a subset of the full dataset for demonstration purposes"),
29
+ datasets.BuilderConfig(name="full_data", version=VERSION, description="This is the complete dataset"),
30
+ ]
31
+ DEFAULT_CONFIG_NAME = "example"
32
+
33
  def _info(self):
 
 
34
  return datasets.DatasetInfo(
35
  description=_DESCRIPTION,
36
  features=datasets.Features(
 
50
  homepage = _HOMEPAGE,
51
  license = _LICENSE,
52
  citation = _CITATION
53
+
54
+ )
55
 
56
  def _split_generators(self, dl_manager):
57
+ """Returns SplitGenerators."""
58
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the
 
59
  s3_series_paths = []
60
  s3_individual_paths = []
61
+ if self.config.name == 'example':
62
+ manifest_file = example_manifest_file
63
+ else:
64
+ manifest_file = full_manifest_file
65
+
66
  with open(manifest_file, 'r') as file:
67
+ for line in file:
68
+ match = re.search(r'cp (s3://[\S]+) .', line)
69
+ if match:
70
+ s3_series_paths.append(match.group(1)[:-2]) # Deleting the '/*' in directories
71
  for series in s3_series_paths:
72
  for content in fs.ls(series):
73
+ s3_individual_paths.append(fs.info(content)['Key'])
74
 
75
+ random.shuffle(s3_individual_paths)
76
 
77
  # Define the split sizes
78
  train_size = int(0.7 * len(s3_individual_paths))
 
108
 
109
  def _generate_examples(self, paths, split):
110
  """Yields examples."""
111
+ # TODO: This method will yield examples, i.e. rows in the dataset.
112
  for path in paths:
113
  key = path
114
  with fs.open(path, 'rb') as f:
115
  dicom_data = pydicom.dcmread(f)
116
  pixel_array = dicom_data.pixel_array
 
117
  # Adjust for MONOCHROME1 to invert the grayscale values
118
  if dicom_data.PhotometricInterpretation == "MONOCHROME1":
119
  pixel_array = np.max(pixel_array) - pixel_array