Update README.md
Browse files
README.md
CHANGED
@@ -160,33 +160,37 @@ dataloader = DataLoader(
|
|
160 |
|
161 |
# Iterate over the full dataset and store features each time 16278 input images have been processed
|
162 |
slide_features = []
|
|
|
163 |
for i, (slide_ids, tile_ids, imgs) in tqdm(
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
#
|
169 |
-
|
170 |
-
|
171 |
-
#
|
172 |
-
#
|
173 |
-
if all(slide_id ==
|
174 |
batch_stack = process_imgs(imgs, tile_ids)
|
175 |
slide_features.append(batch_stack)
|
176 |
-
|
177 |
-
|
178 |
-
|
|
|
|
|
|
|
|
|
179 |
else:
|
180 |
-
#
|
181 |
-
mask = (np.array(slide_ids) !=
|
182 |
idx = mask.argmax()
|
|
|
183 |
batch_stack = process_imgs(imgs[:idx], tile_ids[:idx])
|
184 |
slide_features.append(batch_stack)
|
185 |
-
save_features(slide_features, slide_id=
|
186 |
-
|
187 |
-
|
188 |
-
batch_stack = process_imgs(imgs[idx:], tile_ids[idx:])
|
189 |
-
slide_features = [batch_stack]
|
190 |
```
|
191 |
|
192 |
# License
|
|
|
160 |
|
161 |
# Iterate over the full dataset and store features each time 16278 input images have been processed
|
162 |
slide_features = []
|
163 |
+
|
164 |
for i, (slide_ids, tile_ids, imgs) in tqdm(
|
165 |
+
enumerate(dataloader),
|
166 |
+
total=ceil(num_slides * num_tiles / batch_size),
|
167 |
+
desc="Extracting features"
|
168 |
+
):
|
169 |
+
# Detect the current slide
|
170 |
+
current_slide_id = slide_ids[0]
|
171 |
+
|
172 |
+
# If all tiles from the current batch belongs to the same slide,
|
173 |
+
# we just add the batch features to the running list
|
174 |
+
if all(slide_id == current_slide_id for slide_id in slide_ids):
|
175 |
batch_stack = process_imgs(imgs, tile_ids)
|
176 |
slide_features.append(batch_stack)
|
177 |
+
# If `slide_features` contains 16,278 tiles features, we export it
|
178 |
+
if len(slide_features) == ceil(num_tiles / batch_size):
|
179 |
+
save_features(slide_features, slide_id=current_slide_id)
|
180 |
+
# And initialize `slide_features` as an empty list
|
181 |
+
slide_features = []
|
182 |
+
continue
|
183 |
+
# The current batch contains tiles from current (N) and N+1 slide
|
184 |
else:
|
185 |
+
# We get the maximum index at which tiles all belong to slide N
|
186 |
+
mask = (np.array(slide_ids) != current_slide_id)
|
187 |
idx = mask.argmax()
|
188 |
+
# Then export the slide features with the remaining idx features
|
189 |
batch_stack = process_imgs(imgs[:idx], tile_ids[:idx])
|
190 |
slide_features.append(batch_stack)
|
191 |
+
save_features(slide_features, slide_id=current_slide_id)
|
192 |
+
# And initialize with (batch_size - idx) tiles features from slide N+1
|
193 |
+
slide_features = [process_imgs(imgs[idx:], tile_ids[idx:])]
|
|
|
|
|
194 |
```
|
195 |
|
196 |
# License
|