tf.app.run()错误

时间:2017-06-27 06:12:39

标签: python exception error-handling tensorflow

我在main.py中有这行代码:

if __name__ == "__main__":
    tf.app.run() 

但它抛出了异常:

ValueError: Iteration of zero-sized operands is not enabled

为什么会这样?

这是整个代码:

import tensorflow as tf
import config
import os
from urllib.request import urlretrieve
from zipfile import ZipFile
from dataset.dataset import Dataset
from network.eval import Learning

FLAGS = tf.app.flags.FLAGS
data_dir = config.data_dir
tmp_zip_adr = config.tmp_zip_adr
dataset_urls = config.dataset_urls


def download_dataset_if_needed():
    def download_and_unzip(zipurls):
        for url in zipurls:
            print("Downloading {}".format(url))
            fpath, _ = urlretrieve(url, tmp_zip_adr)
            zf = ZipFile(fpath)
            zf.extractall(data_dir)
            zf.close()
            os.remove(fpath)
        print("Dataset downloaded into 'dataset/data' folder")

    if not os.path.exists(data_dir) or FLAGS.download:
        os.makedirs(data_dir)
        print("Downloading dataset")
        download_and_unzip(dataset_urls)


def main(argv=None):
    download_dataset_if_needed()
    if FLAGS.update or not os.path.exists(data_dir + 'segmented_set1'):
        print("Starting processing binary dataset")
        Dataset().create_dataset(data_dir + "segmented_set?/*.avi")
    Learning()


if __name__ == '__main__':
    tf.app.run()

这就是整个错误:

Traceback (most recent call last):   File
"C:\Users\asus\Desktop\cnn-rnn-master\cnn-rnn-master\main.py", line
41, in <module>
 tf.app.run()   File "C:\Users\asus\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\platform\app.py",
line 48, in run
 _sys.exit(main(_sys.argv[:1] + flags_passthrough))   File "C:\Users\asus\Desktop\cnn-rnn-master\cnn-rnn-master\main.py", line
37, in main
 Learning()   File "C:\Users\asus\Desktop\cnn-rnn-master\cnn-rnn-master\network\eval.py",
line 12, in __init__
 self.train_reader = Reader.Reader("dataset/data/segmented_set1/*.tfr")   File
"C:\Users\asus\Desktop\cnn-rnn-master\cnn-rnn-master\dataset\Reader.py",
line 13, in __init__
 self.init_dataset()   File "C:\Users\asus\Desktop\cnn-rnn-master\cnn-rnn-master\dataset\Reader.py",
line 53, in init_dataset
 self.iterator = np.nditer(self.files) ValueError: Iteration of zero-sized operands is not enabled

我使用https://github.com/tensorflow/tensorflow/blob/9dc6c17797c065796603d9259b2aa57b3c07ff71/tensorflow/python/platform/app.py#L22中的代码逐行浏览了tf.app.run(),run(main=None, argv=None)

中的这一行
_sys.exit(main(_sys.argv[:1] + flags_passthrough))

发出错误

Traceback (most recent call last):
  File "<pyshell#48>", line 1, in <module>
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
TypeError: 'NoneType' object is not callable

0 个答案:

没有答案