python数据类型的操作

时间:2017-01-01 11:57:29

标签: python tensorflow

我是python和tensorflow的新手。如何检查可以对变量执行哪些操作?我试图将图像存储到列表中。我想知道它的大小只是为了确认。

这是从网站上获取的代码。

# Typical setup to include TensorFlow.
import tensorflow as tf

# Make a queue of file names including all the JPEG images files in the relative
# image directory.
filename_queue = tf.train.string_input_producer(
    tf.train.match_filenames_once("./images/*.jpg"))

# Read an entire image file which is required since they're JPEGs, if the images
# are too large they could be split in advance to smaller files or use the Fixed
# reader to split up the file.
image_reader = tf.WholeFileReader()

print(len(filename_queue))

我在下面收到了错误消息。这是函数string_input_producer https://www.tensorflow.org/api_docs/python/io_ops/input_pipeline#string_input_producer的网站,它确实说它返回一个列表,所以我不确定我做错了什么

Traceback (most recent call last):
  File "tf_load_jpg.py", line 14, in <module>
    print(len(filename_queue))
TypeError: object of type 'FIFOQueue' has no len()

1 个答案:

答案 0 :(得分:1)

如评论中所述,您应该使用dir(filename_queue)来检查对象中的函数集。这将输出以下内容 -

['__class__', '__delattr__', '__dict__', '__doc__', '__format__', 
 '__getattribute__', '__hash__', '__init__', '__module__', '__new__',
 '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
 '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 
 '_check_enqueue_dtypes', '_dequeue_return_value', '_dtypes',
 '_name', '_names', '_queue_ref', '_scope_vals', '_shapes',
 'close', 'dequeue', 'dequeue_many', 'dequeue_up_to', 'dtypes',
 'enqueue', 'enqueue_many', 'from_list', 'name', 'names',
 'queue_ref', 'shapes', 'size']

利用size()功能获取结果。您可以阅读有关FIFOQueue的更多信息。