forked from calum-green/OpenLSR-X
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataset.py
More file actions
1980 lines (1631 loc) · 54.7 KB
/
dataset.py
File metadata and controls
1980 lines (1631 loc) · 54.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# import numpy as np
from torch.utils.data import Dataset, ConcatDataset
from porespy_funcs import generator, float32_transform
from porespy_funcs_3d import image_transform
import torch
import pytorch_lightning as pl
from torch.utils.data import DataLoader, random_split
import imageio
from matplotlib.colors import Normalize
import h5py
import numpy as np
import gc
import cv2
import os
from torchvision.transforms import Resize, InterpolationMode
def data_processor(dataset_size, image_size, lf=False, valid=False, test=False):
"""
This function does all pre-processing for passing to DatasetObject class
This is used for generating corresponding high/low pairs of synthetic
PoreSpy data
dataset_size = size of dataset
image_size = size of images
seed = random seed
lf = Bool (low-feature or high_feature)
Returns tuple of low-res, high_res tensor
Output -> tuple(torch.Tensor([C,H,W],dtype=float32))
"""
low_res = []
high_res = []
for i in range(0, dataset_size):
if not valid:
seed = i
elif valid:
seed = i + 10000
elif test:
seed = i + 50000
high, low = generator(size=image_size, seed=seed, lf=lf)
# convert to Tensors
high = float32_transform(high)
low = float32_transform(low)
low_res += low
high_res += high
# self.low_res/high_res contain 16bit tensors of all images in dataset_size
return torch.stack(low_res), torch.stack(high_res)
class DatasetObject(Dataset):
"""
This class takes takes input as low-res and high-res arrays,
then creates a Dataset object with them as high-res and low-res
tensors
Input: np.array
Output: torch.Tensor([B,C,H,W])
"""
def __init__(self, low_res, high_res):
super(DatasetObject, self).__init__()
# load low_res and high_res stacks
self.low_res = low_res
self.high_res = high_res
def __len__(self):
return len(self.high_res)
def __getitem__(self, index):
return self.low_res[index], self.high_res[index]
class MyDataModule(pl.LightningDataModule):
"""
This defines my Data module, which builds upon the DatasetObject class.
It defines all of the preprocessing required,
then also builds the correct dataloaders
1) Use data_processor() to generate high/low res images for test/train
2) Use DatasetObject to create Dataset objects
3) Define the train/test/validation dataloaders using DataLoader
All of the global parameters for the dataset are defined below in the __init__
1) data_processor() takes:
dataset_size = size of dataset
image_size = size of images
lf = Bool (low-feature or high_feature)
2) DatasetObject takes: high_res, low_res from above
3) DataLoader takes:
dataset object from above
batch_size
num_workers
pin_memory
persistent_workers
"""
def __init__(
self,
dataset_size,
valid_size,
test_size,
image_size,
lf,
batch_size,
num_workers,
pin_memory,
persistent_workers,
):
super().__init__()
self.dataset_size = dataset_size
self.valid_size = valid_size
self.test_size = test_size
self.image_size = image_size
self.lf = lf
self.batch_size = batch_size
self.num_workers = num_workers
self.pin_memory = pin_memory
self.persistent_workers = persistent_workers
def setup(self, stage):
if stage == "fit":
low_train, high_train = data_processor(
dataset_size=self.dataset_size,
image_size=self.image_size,
lf=self.lf,
valid=False,
)
self.train = DatasetObject(low_train, high_train)
low_valid, high_valid = data_processor(
dataset_size=self.valid_size,
image_size=self.image_size,
lf=self.lf,
valid=True,
)
self.valid = DatasetObject(low_valid, high_valid)
if stage == "test":
low_test, high_test = data_processor(
dataset_size=self.test_size,
image_size=self.image_size,
lf=self.lf,
test=True,
)
self.test = DatasetObject(low_test, high_test)
if stage == "predict":
low_predict, high_predict = data_processor(
dataset_size=self.test_size,
image_size=self.image_size,
lf=self.lf,
test=True,
)
self.predict = DatasetObject(low_predict, high_predict)
def train_dataloader(self):
return DataLoader(
self.train,
batch_size=self.batch_size,
num_workers=self.num_workers,
pin_memory=self.pin_memory,
persistent_workers=self.persistent_workers,
)
def val_dataloader(self):
return DataLoader(
self.valid,
batch_size=1,
num_workers=1,
pin_memory=self.pin_memory,
persistent_workers=self.persistent_workers,
)
def test_dataloader(self):
return DataLoader(
self.test,
batch_size=1,
num_workers=1,
pin_memory=self.pin_memory,
persistent_workers=self.persistent_workers,
)
def predict_dataloader(self):
return DataLoader(
self.predict,
batch_size=1,
num_workers=1,
pin_memory=self.pin_memory,
persistent_workers=self.persistent_workers,
)
class PoreSpy3D_Volume(pl.LightningDataModule):
"""
The purpose of this class is to load the 3D PoreSpy data
The data will be loaded, and processed into corresponding
high and low-res pairs, and also loaded orthogonally
Task list:
1) Load the tiff files
2) Create Dataset objetcs using DatasetObject class
3) Create DataLoader objects ready to be passed to model
"""
def __init__(
self,
high_file,
low_file,
low_ortho1_file,
low_ortho2_file,
dataset_size,
image_size,
batch_size,
num_workers,
pin_memory,
persistent_workers,
):
super().__init__()
self.high_file = high_file
self.low_file = low_file
self.low_ortho1_file = low_ortho1_file
self.low_ortho2_file = low_ortho2_file
self.dataset_size = dataset_size
self.image_size = image_size
self.batch_size = batch_size
self.num_workers = num_workers
self.pin_memory = pin_memory
self.persistent_workers = persistent_workers
def setup(self, stage):
if stage == "fit":
# training 1st
self.high_res = []
self.low_res = []
high = imageio.volread(self.high_file)
low = imageio.volread(self.low_file)
for i in range(self.dataset_size):
high_slice = high[
i,
self.image_size : self.image_size * 2,
self.image_size : self.image_size * 2,
]
low_slice = low[
i,
self.image_size // 4 : self.image_size // 4 * 2,
self.image_size // 4 : self.image_size // 4 * 2,
]
high_res = image_transform(high_slice)
low_res = image_transform(low_slice)
self.high_res += high_res
self.low_res += low_res
self.train = DatasetObject(self.low_res, self.high_res)
# validation
high_valid = high
low_valid = imageio.volread(self.low_ortho1_file)
slices = [0, 12, 72, 160, 292, 372, 500, 624, 812, 920]
self.high_valid = []
self.low_valid = []
for slice in slices:
high_ortho = high_valid[0 : self.image_size, slice, 0 : self.image_size]
low_ortho = low_valid[
0 : self.image_size // 4, slice, 0 : self.image_size // 4
]
high_res = image_transform(high_ortho)
low_res = image_transform(low_ortho)
self.high_valid += high_res
self.low_valid += low_res
self.valid = DatasetObject(self.low_valid, self.high_valid)
if stage == "test":
slices = [0, 12, 72, 160, 292, 372, 500, 624, 812, 920]
high_test = imageio.volread(self.high_file)
low_test = imageio.volread(self.low_ortho2_file)
self.high_test = []
self.low_test = []
for slice in slices:
high_ortho2 = high_test[0 : self.image_size, 0 : self.image_size, slice]
low_ortho2 = low_test[
0 : self.image_size // 4, 0 : self.image_size // 4, slice
]
high_res = image_transform(high_ortho2)
low_res = image_transform(low_ortho2)
self.high_test += high_res
self.low_test += low_res
self.test = DatasetObject(self.low_test, self.high_test)
if stage == "predict":
pass
def train_dataloader(self):
return DataLoader(
self.train,
batch_size=self.batch_size,
num_workers=self.num_workers,
pin_memory=self.pin_memory,
persistent_workers=self.persistent_workers,
)
def val_dataloader(self):
return DataLoader(
self.valid,
batch_size=1,
num_workers=1,
pin_memory=self.pin_memory,
persistent_workers=self.persistent_workers,
)
def test_dataloader(self):
return DataLoader(
self.test,
batch_size=1,
num_workers=1,
pin_memory=self.pin_memory,
persistent_workers=self.persistent_workers,
)
def predict_dataloader(self):
pass
# I13 XCT functions
class CustomNormalize(Normalize):
def __init__(self, vmin=None, vmax=None, clip=True):
super().__init__(vmin, vmax, clip)
def __call__(self, value, clip=None):
result = super().__call__(value, clip)
return result
# defines the colormaps for the different datasets and resolutions
# norm26 = CustomNormalize(vmin=-5.41e-4, vmax=1.68e-3)
norm16 = CustomNormalize(vmin=-5.23e-4, vmax=1.11e-3)
norm81 = CustomNormalize(vmin=-2.50e-4, vmax=6.79e-4)
def norm_01(volume, lower_bound, upper_bound):
"""
Takes a volume and normalises the volume between [0,1]
This preserves the dynamic range of the images without clipping
Specify the lower and upper bounds for the percentile
"""
# vol_min, vol_max = np.min(volume), np.max(volume)
vol_min, vol_max = np.percentile(volume, lower_bound), np.percentile(
volume, upper_bound
)
return CustomNormalize(vmin=vol_min, vmax=vol_max)(volume)
def i13_xct_processor(low_file, high_file, dataset_size):
"""
The function takes the low-res and high-res files as input, loads them
and processes them into a torch.stack of low_res, high_res images that are
aligned spatially.
The output is passsed to create the I13XCTDatasetModule object
Input: High and Low-res files
Output: tuple(torch.stack(low_res), torch.stackk(high_res)
Arguments:
low_file = low-res filename
high_file = high-res filename
dataset_size = required size of dataset
Workflow:
1) Load the data
2) Normalise each dataset between [0,1]
3) Align the data and define the dataset size
4) Apply colormap to the data
"""
# first load the data
low_data = np.transpose(
h5py.File(low_file, "r")["4-TomopyRecon-tomo"]["data"], (1, 2, 0)
)
high_data = np.transpose(
h5py.File(high_file, "r")["4-TomopyRecon-tomo"]["data"], (1, 2, 0)
)
# apply the normalisation
# data is float32 here and is normalised [0,1]
# also align the dataset
# low_data[894][1010:1650,858:1498], high_data[804][763:2043,466:1746]
low_data_norm = norm16(low_data[:, 1010:1650, 858:1498])
# low_data_norm = norm_01(low_data[:, 1010:1650, 858:1498], 0.005, 99.995)
del low_data
high_data_norm = norm81(high_data[:, 763:2043, 466:1746])
# high_data_norm = norm_01(high_data[:, 763:2043, 466:1746], 0.005, 99.995)
del high_data
gc.collect()
# data is loaded, normalised and aligned
# now define the dataset
# define dataset sizes and image indices for alignment
dataset_size = dataset_size
offset = 50
low_idx = 895 - offset
high_idx = 801 - (offset * 2)
low_volume = low_data_norm[low_idx : low_idx + dataset_size, :, :]
del low_data_norm
high_volume = high_data_norm[
high_idx : high_idx + (dataset_size * 2),
:,
:,
]
del high_data_norm
gc.collect()
# 3D np.array -> torch.Tensor([C,H,W])
low_stack = torch.tensor(low_volume)
high_stack = torch.tensor(high_volume)
# I now have the volumes, normalised and aligned
return low_stack, high_stack
def i13_xct_manalign_processor(
low_file, high_file, dataset_size, xy=False, xz=False, yz=False
):
"""
Defines the processing for the manually aligned I13 data
"""
# first load the data
low_data = np.transpose(
h5py.File(low_file, "r")["4-TomopyRecon-tomo"]["data"], (1, 2, 0)
)
high_data = np.transpose(
h5py.File(high_file, "r")["4-TomopyRecon-tomo"]["data"], (1, 2, 0)
)
# apply the normalisation
# data is float32 here and is normalised [0,1]
# also align the dataset
# low_data[894][1010:1650,858:1498], high_data[804][763:2043,466:1746]
low_data_norm = norm16(low_data[:, 1010:1650, 858:1498])
# low_data_norm = norm_01(low_data[:, 1010:1650, 858:1498], 0.005, 99.995)
del low_data
high_data_norm = norm81(high_data[:, 763:2043, 466:1746])
# high_data_norm = norm_01(high_data[:, 763:2043, 466:1746], 0.005, 99.995)
del high_data
gc.collect()
# data is loaded, normalised and aligned
# now define the dataset
# define dataset sizes and image indices for alignment
dataset_size = dataset_size
offset = 50
low_idx = 895 - offset
high_idx = 801 - (offset * 2)
low_volume = low_data_norm[low_idx : low_idx + dataset_size, :, :]
del low_data_norm
high_volume = high_data_norm[
high_idx : high_idx + (dataset_size * 2),
:,
:,
]
del high_data_norm
gc.collect()
# 3D np.array -> torch.Tensor([C,H,W])
low_stack = torch.tensor(low_volume)
high_stack = torch.tensor(high_volume)
low_slices = [
1,
4,
9,
11,
15,
17,
23,
25,
28,
31,
38,
44,
49,
54,
57,
63,
67,
71,
76,
82,
87,
90,
92,
98,
104,
107,
114,
120,
128,
134,
137,
142,
148,
155,
162,
164,
171,
181,
185,
190,
197,
199,
205,
215,
220,
225,
231,
234,
242,
247,
251,
256,
258,
264,
267,
273,
281,
287,
293,
295,
298,
301,
306,
308,
314,
320,
324,
330,
339,
344,
349,
355,
361,
366,
370,
375,
378,
382,
385,
387,
396,
401,
404,
413,
420,
426,
432,
438,
444,
451,
459,
467,
471,
476,
485,
489,
492,
500,
507,
510,
516,
522,
524,
533,
540,
546,
553,
559,
564,
569,
576,
582,
592,
597,
602,
607,
610,
616,
624,
628,
]
high_slices = [
2,
5,
11,
13,
17,
19,
25,
27,
30,
33,
40,
46,
51,
56,
59,
65,
70,
74,
79,
85,
90,
93,
95,
101,
107,
110,
117,
123,
131,
137,
140,
145,
152,
159,
166,
168,
175,
185,
189,
194,
201,
203,
210,
220,
225,
230,
236,
239,
247,
252,
256,
261,
263,
269,
273,
279,
287,
292,
299,
301,
303,
307,
312,
314,
320,
326,
330,
336,
345,
351,
356,
362,
367,
373,
377,
382,
385,
389,
392,
394,
403,
408,
411,
421,
428,
434,
440,
446,
452,
459,
467,
475,
479,
485,
493,
498,
501,
508,
516,
519,
524,
531,
533,
542,
549,
556,
562,
569,
574,
579,
587,
592,
602,
607,
612,
617,
620,
627,
634,
640,
]
low_aligned_stack = low_stack[torch.tensor(np.array(low_slices) - 1)]
high_aligned_stack = high_stack[torch.tensor((np.array(high_slices) - 1) * 2)]
if yz is True:
return low_aligned_stack, high_aligned_stack
elif xy is True:
return torch.permute(
low_stack[low_slices[0] - 1 : low_slices[-1] - 1], (2, 0, 1)
), torch.permute(
high_stack[high_slices[0] - 1 : (high_slices[-1] - 1) * 2], (2, 0, 1)
)
elif xz is True:
return torch.permute(
low_stack[low_slices[0] - 1 : low_slices[-1] - 1], (1, 0, 2)
), torch.permute(
high_stack[high_slices[0] - 1 : (high_slices[-1] - 1) * 2], (1, 0, 2)
)
def i13_test_data_processor(low_file, high_file):
low_data = h5py.File(low_file, "r")["data"]
high_data = h5py.File(high_file, "r")["data"]
print(low_data.shape, high_data.shape)
print(type(low_data), type(high_data))
return torch.tensor(low_data), torch.tensor(high_data)
def i13_xct_pred_processor(low_file, high_file, xy=False, xz=False, yz=False):
low_data = np.transpose(
h5py.File(low_file, "r")["4-TomopyRecon-tomo"]["data"], (1, 2, 0)
)
high_data = np.transpose(
h5py.File(high_file, "r")["4-TomopyRecon-tomo"]["data"], (1, 2, 0)
)
low_data_norm = norm16(low_data[:, 1010:1650, 858:1498])
# low_data_norm = norm_01(low_data[:, 1010:1650, 858:1498], 0.005, 99.995)
del low_data
high_data_norm = norm81(high_data[:, 763:2043, 466:1746])
# high_data_norm = norm_01(high_data[:, 763:2043, 466:1746], 0.005, 99.995)
del high_data
gc.collect()
# define dataset sizes and image indices for alignment
low_size = 640
high_size = 1280
low_idx = 895 - 50
high_idx = 801 - (50 * 2)
low_volume = low_data_norm[
low_idx : (low_idx + low_size), :, :
] # [640,640,640] here
del low_data_norm
high_volume = high_data_norm[
high_idx : (high_idx + high_size), :, :
] # [1280,1280,1280] here
del high_data_norm
gc.collect()
# 3D np.array -> torch.Tensor([C,H,W])
if xy is True:
low_pred = torch.tensor(np.transpose(low_volume, (2, 0, 1)))
high_pred = torch.tensor(np.transpose(high_volume, (2, 0, 1))[::2, :, :])
if xz is True:
low_pred = torch.tensor(np.transpose(low_volume, (1, 0, 2)))
high_pred = torch.tensor(np.transpose(high_volume, (1, 0, 2))[::2, :, :])
if yz is True:
low_pred = torch.tensor(low_volume)
high_pred = torch.tensor(high_volume[::2, :, :])
# I now have the volumes, normalised and aligned
return low_pred, high_pred
class I13XCTDataModule(pl.LightningDataModule):
"""
This module defines the dataloader process for the I13 XCT data that I collected
It makes use of the DatasetObject class to create the dataset objects.
The I13 data will exist in the high-res and low-res 3D volume.
Workflow:
1) Data processing (refer to Jupyter notebook on aligning/colormap)
- need to create a new one
2) Create DatasetObject of the high/low res data
- should work provided I feed same input as output of data_processor function
3) Create DataLoader objects for training/validation/testing
- follow process from above with the different test/train/valid datasets
"""
def __init__(
self,
low_file,
high_file,
dataset_size,
train_size,
valid_size,
test_size,
batch_size,
num_workers,
pin_memory,
persistent_workers,
train_axis="yz",
predict_axis="yz",
testing=False,
predict=False,
manual_train=False,
):
super().__init__()
self.low_file = low_file
self.high_file = high_file
self.testing = testing
self.dataset_size = dataset_size
self.train_size = int(train_size * dataset_size)
self.valid_size = int(valid_size * dataset_size)
self.test_size = int(test_size * dataset_size)
self.batch_size = batch_size
self.num_workers = num_workers
self.pin_memory = pin_memory
self.persistent_workers = persistent_workers
self.train_axis = train_axis
self.predict_axis = predict_axis
self.testing = testing
self.predict = predict
self.remainder = self.dataset_size - (
self.train_size + self.valid_size + self.test_size
)
self.manual_train = manual_train
def setup(self, stage):
if not self.testing:
low_stack, high_stack = i13_xct_processor(
self.low_file, self.high_file, self.dataset_size
)
elif self.testing:
low_stack, high_stack = i13_test_data_processor(
self.low_file, self.high_file
)
# define the sampler
# create train, test, valid datasets
sampler = torch.Generator().manual_seed(42)
if not self.manual_train:
stack = DatasetObject(low_stack, high_stack[::2, :, :])
train, valid, test, _ = random_split(
stack,
lengths=[
self.train_size,
self.valid_size,
self.test_size,
self.remainder,
],
generator=sampler,
)
elif self.manual_train and self.train_axis != "mixed":
low_stack, high_stack = i13_xct_manalign_processor(
self.low_file,
self.high_file,
self.dataset_size,
yz=True if self.train_axis == "yz" else False,
xy=True if self.train_axis == "xy" else False,
xz=True if self.train_axis == "xz" else False,
)
low_stack = low_stack
high_stack = high_stack[::2, :, :]
# ensure that each slice is the correct size and resize if necessary
if (low_stack.shape[1], low_stack.shape[2]) != (640, 640):
low_stack = Resize(
size=(640, 640), interpolation=InterpolationMode.BICUBIC
)(low_stack)
if (high_stack.shape[1], high_stack.shape[2]) != (1280, 1280):
high_stack = Resize(
size=(1280, 1280), interpolation=InterpolationMode.BICUBIC
)(high_stack)
stack = DatasetObject(low_stack, high_stack)
if self.train_axis == "yz":
train, valid, test = random_split(
stack,
lengths=[100, 10, 10],
generator=sampler,
)
elif self.train_axis == "xy" or self.train_axis == "xz":
remainder = stack.__len__() - (100 + 10 + 10)
train, valid, test, _ = random_split(
stack,
lengths=[100, 10, 10, remainder],
generator=sampler,
)
elif self.manual_train and self.train_axis == "mixed":
low_yz, high_yz = i13_xct_manalign_processor(
self.low_file,
self.high_file,
self.dataset_size,
yz=True,
)
low_xy, high_xy = i13_xct_manalign_processor(
self.low_file,
self.high_file,
self.dataset_size,
xy=True,
)
low_xz, high_xz = i13_xct_manalign_processor(
self.low_file,
self.high_file,