@@ -54,7 +54,7 @@ def tqdm(x): return x
54
54
parser .add_argument ('path' , type = str , nargs = 2 ,
55
55
help = ('Path to the generated images or '
56
56
'to .npz statistic files' ))
57
- parser .add_argument ('--batch-size' , type = int , default = 256 ,
57
+ parser .add_argument ('--batch-size' , type = int , default = 50 ,
58
58
help = 'Batch size to use' )
59
59
parser .add_argument ('--dims' , type = int , default = 2048 ,
60
60
choices = list (InceptionV3 .BLOCK_INDEX_BY_DIM ),
@@ -64,16 +64,18 @@ def tqdm(x): return x
64
64
help = 'GPU to use (leave blank for CPU only)' )
65
65
66
66
67
- def get_activations (files , model , batch_size = 64 , dims = 2048 ,
67
+ def get_activations (files , model , batch_size = 50 , dims = 2048 ,
68
68
cuda = False , verbose = False ):
69
69
"""Calculates the activations of the pool_3 layer for all images.
70
70
71
71
Params:
72
72
-- files : List of image files paths
73
73
-- model : Instance of inception model
74
- -- batch_size : the images numpy array is split into batches with
75
- batch size batch_size. A reasonable batch size depends
76
- on the hardware.
74
+ -- batch_size : Batch size of images for the model to process at once.
75
+ Make sure that the number of samples is a multiple of
76
+ the batch size, otherwise some samples are ignored. This
77
+ behavior is retained to match the original FID score
78
+ implementation.
77
79
-- dims : Dimensionality of features returned by Inception
78
80
-- cuda : If set to True, use GPU
79
81
-- verbose : If set to True and parameter out_step is given, the number
@@ -85,6 +87,9 @@ def get_activations(files, model, batch_size=64, dims=2048,
85
87
"""
86
88
model .eval ()
87
89
90
+ if len (files ) % batch_size != 0 :
91
+ print (('Warning: number of images is not a multiple of the '
92
+ 'batch size. Some samples are going to be ignored.' ))
88
93
if batch_size > len (files ):
89
94
print (('Warning: batch size is bigger than the data size. '
90
95
'Setting batch size to data size' ))
@@ -185,7 +190,7 @@ def calculate_frechet_distance(mu1, sigma1, mu2, sigma2, eps=1e-6):
185
190
np .trace (sigma2 ) - 2 * tr_covmean )
186
191
187
192
188
- def calculate_activation_statistics (files , model , batch_size = 64 ,
193
+ def calculate_activation_statistics (files , model , batch_size = 50 ,
189
194
dims = 2048 , cuda = False , verbose = False ):
190
195
"""Calculation of the statistics used by the FID.
191
196
Params:
0 commit comments