(paths, batch_size, cuda, dims)
return fid_value
Calculates the FID of two paths
Calculates the FID of two paths
Calculates the FID of two paths
def calculate_fid_given_paths(paths, batch_size, cuda, dims):
    """Calculates the FID of two paths"""
    for p in paths:
        if not os.path.exists(p):
            raise RuntimeError('Invalid path: %s' % p)

    block_idx = InceptionV3.BLOCK_INDEX_BY_DIM[dims]

    if cuda:
        dtype = torch.cuda.FloatTensor
    else:
        if torch.cuda.is_available():
            print("WARNING: You have a CUDA device, so you should probably set cuda=True")
        dtype = torch.FloatTensor

    inception_model = InceptionV3([block_idx]).type(dtype)

    m1, s1 = _compute_statistics_of_path(paths[0], inception_model, batch_size,
                                         dims, cuda)
    print("1 done")
    m2, s2 = _compute_statistics_of_path(paths[1], inception_model, batch_size,
                                         dims, cuda)
    print("2 done")
    fid_value = calculate_frechet_distance(m1, s1, m2, s2)

    return fid_value
def calculate_fid_given_paths ( paths , batch_size , cuda , dims ) : for p in paths : if not os . path . exists ( p ) : raise RuntimeError ( 'Invalid path: %s' % p ) block_idx = InceptionV3 . BLOCK_INDEX_BY_DIM [ dims ] if cuda : dtype = torch . cuda . FloatTensor else : if torch . cuda . is_available ( ) : print ( "WARNING: You have a CUDA device, so you should probably set cuda=True" ) dtype = torch . FloatTensor inception_model = InceptionV3 ( [ block_idx ] ) . type ( dtype ) m1 , s1 = _compute_statistics_of_path ( paths [ 0 ] , inception_model , batch_size , dims , cuda ) print ( "1 done" ) m2 , s2 = _compute_statistics_of_path ( paths [ 1 ] , inception_model , batch_size , dims , cuda ) print ( "2 done" ) fid_value = calculate_frechet_distance ( m1 , s1 , m2 , s2 ) return fid_value