cell-data-loader 0.0.2__tar.gz → 0.0.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cell_data_loader
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Converts general images of cells into formats and labels for deep learning pipelines
5
5
  Project-URL: Homepage, https://github.com/mleming/CellDataLoader
6
6
  Author-email: Matt Leming <mleming@mgh.harvard.edu>
@@ -10,6 +10,8 @@ Keywords: biomedical,cell,cell image,cellpose,csz,dataloader
10
10
  Requires-Python: >=3.8
11
11
  Requires-Dist: numpy
12
12
  Requires-Dist: opencv-python>=4.5.4
13
+ Requires-Dist: pillow
14
+ Requires-Dist: scikit-image
13
15
  Requires-Dist: scipy
14
16
  Requires-Dist: slideio==2.4.1
15
17
  Requires-Dist: torch
@@ -23,7 +25,7 @@ Cell Data Loader is a simple AI support tool in Python that can take in images o
23
25
 
24
26
  To install Cell Data Loader, simply type into a standard UNIX terminal
25
27
 
26
- pip install cell-data-loader==0.0.1
28
+ pip install cell-data-loader
27
29
 
28
30
  The simplest way to use Cell Data Loader is to instantiate a dataloader as such:
29
31
 
@@ -90,8 +92,10 @@ imfolder = '/path/to/folder'
90
92
  dataloader = CellDataloader(imfolder,
91
93
  dim = (64,64),
92
94
  batch_size = 32,
93
- dtype = "numpy",
94
- n_channels = 3, #This is detected in the first read image by default, if not provided; it re-samples all images to force this number of channels
95
+ dtype = "numpy", # Can also be "torch"
96
+ label_regex = None,
97
+ n_channels = 3, # This is detected in the first read image by default, if not provided; it re-samples all images to force this number of channels
98
+ match_labels = False, # Outputs proportional amounts of each label in the dataset
95
99
  )
96
100
  ~~~
97
101
 
@@ -101,15 +105,22 @@ Dependencies
101
105
 
102
106
  Strict dependencies:
103
107
 
104
- scipy
105
108
  numpy
106
- pytorch
107
- open-cv
109
+ torch
110
+ torchvision
111
+ opencv-python>=4.5.4
112
+ slideio==2.4.1
113
+ scipy
114
+ scikit-image
115
+ pillow
108
116
 
109
117
  Soft dependencies:
110
118
 
111
119
  CellPose # For cell segmentation support
112
- slideio # For reading .SVS and .CZI files
120
+ Tensorflow
121
+
122
+ Note that some of the dependencies are not strict and vary depending on usage. Numpy is a hard requirement, but Tensorflow is not if the user only uses the Torch capabilities. If the user attempts to load cell images in "cell" mode without a working Cellpose installation, CellDataLoader will throw an error. Cellpose needs be be installed separately to use "cell" mode:
113
123
 
124
+ pip install cellpose
114
125
 
115
- Note that some of the dependencies are not strict and vary depending on usage. Numpy is a hard requirement, but Torch is not if the user only uses Tensorflow. If the user attempts to load cell images in "cell" mode without a working Cellpose installation, CellDataLoader will throw an error.
126
+ And GPU integration is a separate matter.
@@ -5,7 +5,7 @@ Cell Data Loader is a simple AI support tool in Python that can take in images o
5
5
 
6
6
  To install Cell Data Loader, simply type into a standard UNIX terminal
7
7
 
8
- pip install cell-data-loader==0.0.1
8
+ pip install cell-data-loader
9
9
 
10
10
  The simplest way to use Cell Data Loader is to instantiate a dataloader as such:
11
11
 
@@ -72,8 +72,10 @@ imfolder = '/path/to/folder'
72
72
  dataloader = CellDataloader(imfolder,
73
73
  dim = (64,64),
74
74
  batch_size = 32,
75
- dtype = "numpy",
76
- n_channels = 3, #This is detected in the first read image by default, if not provided; it re-samples all images to force this number of channels
75
+ dtype = "numpy", # Can also be "torch"
76
+ label_regex = None,
77
+ n_channels = 3, # This is detected in the first read image by default, if not provided; it re-samples all images to force this number of channels
78
+ match_labels = False, # Outputs proportional amounts of each label in the dataset
77
79
  )
78
80
  ~~~
79
81
 
@@ -83,15 +85,22 @@ Dependencies
83
85
 
84
86
  Strict dependencies:
85
87
 
86
- scipy
87
88
  numpy
88
- pytorch
89
- open-cv
89
+ torch
90
+ torchvision
91
+ opencv-python>=4.5.4
92
+ slideio==2.4.1
93
+ scipy
94
+ scikit-image
95
+ pillow
90
96
 
91
97
  Soft dependencies:
92
98
 
93
99
  CellPose # For cell segmentation support
94
- slideio # For reading .SVS and .CZI files
100
+ Tensorflow
101
+
102
+ Note that some of the dependencies are not strict and vary depending on usage. Numpy is a hard requirement, but Tensorflow is not if the user only uses the Torch capabilities. If the user attempts to load cell images in "cell" mode without a working Cellpose installation, CellDataLoader will throw an error. Cellpose needs be be installed separately to use "cell" mode:
95
103
 
104
+ pip install cellpose
96
105
 
97
- Note that some of the dependencies are not strict and vary depending on usage. Numpy is a hard requirement, but Torch is not if the user only uses Tensorflow. If the user attempts to load cell images in "cell" mode without a working Cellpose installation, CellDataLoader will throw an error.
106
+ And GPU integration is a separate matter.
@@ -6,11 +6,18 @@ import numpy
6
6
  import os
7
7
 
8
8
  def example_numpy():
9
+
10
+ """
11
+ Replace whese with folders locally on your computer -- script will not work
12
+ without new folders.
13
+ """
9
14
  wd = os.path.dirname(os.path.realpath(__file__))
10
- imfolder_test = os.path.join(os.path.dirname(wd),'cell_data_loader_data','3368914_4_non_tumor')
11
- imfolder_train = os.path.join(os.path.dirname(wd),'cell_data_loader_data','4173633_5')
12
- model = resnet50()
15
+ imfolder_test = os.path.join(os.path.dirname(wd),'cell_data_loader_data',
16
+ '3368914_4_non_tumor')
17
+ imfolder_train = os.path.join(os.path.dirname(wd),'cell_data_loader_data',
18
+ '4173633_5')
13
19
 
20
+ model = resnet50()
14
21
  model = tf.keras.applications.resnet50.ResNet50(
15
22
  include_top=True,
16
23
  weights='imagenet',
@@ -36,7 +43,6 @@ def example_numpy():
36
43
  # Test
37
44
 
38
45
  model.eval()
39
-
40
46
  dataloader_test = CellDataloader(imfolder_test,imfolder_train,dtype="torch",
41
47
  verbose=False)
42
48
  total_images = 0
@@ -6,9 +6,16 @@ import torch
6
6
  import os
7
7
 
8
8
  def example_torch():
9
+
10
+ """
11
+ Replace whese with folders locally on your computer -- script will not work
12
+ without new folders.
13
+ """
9
14
  wd = os.path.dirname(os.path.realpath(__file__))
10
- imfolder_test = os.path.join(os.path.dirname(wd),'cell_data_loader_data','3368914_4_non_tumor')
11
- imfolder_train = os.path.join(os.path.dirname(wd),'cell_data_loader_data','4173633_5')
15
+ imfolder_test = os.path.join(os.path.dirname(wd),'cell_data_loader_data',
16
+ '3368914_4_non_tumor')
17
+ imfolder_train = os.path.join(os.path.dirname(wd),'cell_data_loader_data',
18
+ '4173633_5')
12
19
  model = resnet50()
13
20
 
14
21
  # Train
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+
3
+ rm -r dist
4
+ python3 -m build --sdist
5
+ twine upload dist/*
@@ -2,7 +2,7 @@
2
2
 
3
3
  name = "cell_data_loader"
4
4
 
5
- version = "0.0.2"
5
+ version = "0.0.3"
6
6
 
7
7
  dependencies = [
8
8
  "numpy",
@@ -10,7 +10,9 @@ dependencies = [
10
10
  "torch",
11
11
  "torchvision",
12
12
  "opencv-python>=4.5.4",
13
- "slideio==2.4.1"
13
+ "slideio==2.4.1",
14
+ "scikit-image",
15
+ "pillow"
14
16
  ]
15
17
  requires-python = ">=3.8"
16
18
 
@@ -174,9 +174,9 @@ class ImageLabelObject(BaseDataset):
174
174
  return imslice
175
175
  elif self.mode == "cell":
176
176
  if len(self.get_cell_box_label()) == 0:
177
- print("len self: %d" % len(self))
177
+ #print("len self: %d" % len(self))
178
178
  return -1
179
- raise Exception("No cells in this image — should not call")
179
+ #raise Exception("No cells in this image — should not call")
180
180
  #warnings.warn("No cells found in %s" % self.filename)
181
181
  #return -1
182
182
  index = index % len(self.get_cell_box_label())
@@ -359,7 +359,8 @@ class CellDataloader():#BaseDataset):
359
359
  if self.dtype == "numpy":
360
360
  self.label_batch = np.zeros((self.batch_size,self.n_labels))
361
361
  elif self.dtype == "torch":
362
- self.label_batch = torch.zeros(self.batch_size,self.n_labels)
362
+ self.label_batch = torch.zeros(self.batch_size,self.n_labels,
363
+ device = self.gpu_ids)
363
364
  sample = self.image_objects[0]
364
365
  if n_channels is None:
365
366
  self.n_channels = sample.get_n_channels()
@@ -151,6 +151,29 @@ class TestSimple(unittest.TestCase):
151
151
  counts[int(np.argmax(y))] += 1
152
152
  self.assertEqual(counts[0],counts[1])
153
153
  self.assertEqual(counts[1],counts[2])
154
+ def test_gpu(self):
155
+ batch_size = 5
156
+ dim = (6,7)
157
+ for dtype in ["torch","numpy"]:
158
+ if dtype == "torch":
159
+ if not torch.cuda.is_available():
160
+ print("No available GPU for torch -- skipping")
161
+ continue
162
+ device = torch.cuda.current_device()
163
+ elif dtype == "numpy":
164
+ continue
165
+ dataset = CellDataloader(imfolder1,imfolder2,imfolder3,dim=dim,
166
+ batch_size=batch_size,dtype=dtype,match_labels=True,
167
+ gpu_ids = device)
168
+ for x,y in dataset:
169
+ if dtype == "torch":
170
+ self.assertEquals(device,x.device.index)
171
+ self.assertEquals(device,y.device.index)
172
+ break
173
+ elif dtype == "numpy":
174
+ break
175
+ else:
176
+ break
154
177
 
155
178
  if __name__ == "__main__":
156
179
  unittest.main()