【问题标题】:Generated circle image preprocessing for TensorflowTensorFlow 生成的圆形图像预处理
【发布时间】:2017-08-10 03:35:24
【问题描述】:

我正在编写一个机器学习程序来识别黑白图像中的圆心。图像生成器脚本在这里:

from __future__ import division
from __future__ import print_function
import numpy as np
from PIL import Image
from random import randint


for n in range(0,400):
#import time
#date_string = time.strftime("%Y-%m-%d-%H:%M:%S")
#Initialize the matrix- Size (100,100)
size = 100
arr = np.zeros((size,size))

#Initialize the Gaussian Properties

x0 = randint(1,100); y0 = randint(1,100); sigmax = randint(1,10); 
sigmay = randint(1,10)

center = (x0,y0)
print (center)
#Create the Gaussian Function

def Gaussian(x,y):
    result = int(round( 255*np.exp(-(x - x0)**2 / (2 * sigmax**2)) * 
    np.exp( -(y - y0)**2 / (2 *sigmay**2))))
    return result

for i in range(size):
    for j in range(size):
        arr[i][j] = Gaussian(i,j)

im = Image.fromarray(arr)
if im.mode !='RGB':
    im = im.convert('RGB')
    #im.show()
    im.save("/home/garrett/train/"+str(n)+".jpeg", "JPEG")

这个脚本输出一个像这样一个黑白圆圈的图像,并且给出中心的标签输出到一个文本文件。我正在使用在https://github.com/tensorflow/models/blob/master/inception/inception/data/build_imagenet_data.py 找到的脚本 作为一个黑匣子来处理我的图像数据以与 Tensorflow 一起使用。但是,当我运行此命令时:

 python build_image_data.py --train_directory=./train --
output_directory=./  --validation_directory=./validate --
labels_file=mylabels.txt   --train_shards=1 --validation_shards=1 --
num_threads=1

我收到以下错误消息:

Saving results to ./
Determining list of input files and labels from ./validate.
Traceback (most recent call last):
  File "build_image_data.py", line 435, in <module>
    tf.app.run()
  File "/home/garrett/anaconda3/lib/python3.6/site-
packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "build_image_data.py", line 429, in main
    FLAGS.validation_shards, FLAGS.labels_file)
  File "build_image_data.py", line 415, in _process_dataset
    filenames, texts, labels = _find_image_files(directory, 
labels_file)
  File "build_image_data.py", line 379, in _find_image_files
    matching_files = tf.gfile.Glob(jpeg_file_path)
  File "/home/garrett/anaconda3/lib/python3.6/site-
packages/tensorflow/python/lib/io/file_io.py", line 332, in 
get_matching_files
    for single_filename in filename
  File "/home/garrett/anaconda3/lib/python3.6/contextlib.py", line 89, 
in __exit__
    next(self.gen)
  File "/home/garrett/anaconda3/lib/python3.6/site-
packages/tensorflow/python/framework/errors_impl.py", line 466, in 
raise_exception_on_not_ok_status
    pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.NotFoundError: ./validate/(33, 
23)

这是正确的方法吗?如果是这样,我做错了什么?如果不是,那么格式化我的数据以与 Tensorflow 一起使用的正确方法是什么?如果有帮助,我计划使用卷积神经网络来识别中心。这可能有点矫枉过正,但在我完成类似的、更复杂的任务之前,更多的是练习。

谢谢,如有任何建议,我们将不胜感激。

【问题讨论】:

    标签: python tensorflow data-processing


    【解决方案1】:

    https://github.com/tensorflow/models/blob/master/inception/inception/data/build_imagenet_data.py 脚本需要一个非常具体的目录结构,其中训练和验证图像位于不同的目录中。您看到的错误似乎是您没有“验证”目录。

    您应该在这里查看https://www.tensorflow.org/api_guides/python/image,了解如何加载 jpeg 图像的示例

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-15
      • 2015-12-27
      • 2013-01-21
      • 1970-01-01
      • 1970-01-01
      • 2011-01-27
      相关资源
      最近更新 更多