tf.app.run() error

邮差的信 提交于 2019-12-25 12:03:08

问题


I have this line of code in my main.py:

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

But it throws out the exception:

ValueError: Iteration of zero-sized operands is not enabled

Why is this?

This is the entire code:

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()

And this is the entire error:

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

I have gone through tf.app.run() line by line using the code found in https://github.com/tensorflow/tensorflow/blob/9dc6c17797c065796603d9259b2aa57b3c07ff71/tensorflow/python/platform/app.py#L22, and this line in run(main=None, argv=None)

_sys.exit(main(_sys.argv[:1] + flags_passthrough))

gives out the error

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

来源:https://stackoverflow.com/questions/44773345/tf-app-run-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!