igul222 / improved_wgan_training

Code for reproducing experiments in "Improved Training of Wasserstein GANs"
MIT License
2.35k stars 668 forks source link

inception_score.py: fixed the issue of ValueError "Cannot iterate over a shape with unknown rank" #81

Open China-LiuXiaopeng opened 5 years ago

China-LiuXiaopeng commented 5 years ago

The inception_scope.py in the tf version =1.11.0 (python 3.6) works well for me. But when I run it in another machine with tf version=1.8.0 (python 3.5), it reports a ValueError "Cannot iterate over a shape with unknown rank" occurring in the code here:

def _inception_score(self):  
    ....
    for o in op.outputs:  
        shape = o.get_shape()  
        shape = [s.value for s in shape]. # error raised

I observed that the problem is perhaps caused by various Tensor type of o, which is with both tf.float32 and tf.bool. However, the bool type of o has the shape of [ ], which could not be correctly executed by the iteration s.value for s in shape iteration, therefore a ValueError raising! We could fix it by the following modifications:

def _inception_score(self):`
    ....
    for o in op.outputs:
        if o.dtype == tf.bool:
            shape = []
        else:
            shape = [s.value for s in o.shape]