afiliot commited on
Commit
3161202
·
verified ·
1 Parent(s): c63a738

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +24 -20
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
- enumerate(dataloader),
165
- total=(num_slides*num_tiles)//batch_size+1,
166
- desc=f"Extracting features"
167
- ):
168
- # Set the reference slide
169
- reference_slide_id = slide_ids[0]
170
-
171
- # Check whether all slide ids are the same inside the batch.
172
- # If yes, it means we have not reached the last batch for a given slide_id.
173
- if all(slide_id == reference_slide_id for slide_id in slide_ids):
174
  batch_stack = process_imgs(imgs, tile_ids)
175
  slide_features.append(batch_stack)
176
- # Otherwise, a batch contains features of 2 different slides.
177
- # First, we need to save the features from slide N-1, and then
178
- # initialize the running `slide_features` list with the features from slide N.
 
 
 
 
179
  else:
180
- # Save features matrix for `reference_slide_id`
181
- mask = (np.array(slide_ids) != reference_slide_id)
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=reference_slide_id)
186
-
187
- # Initialize `slide_features` with the next slide
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