2017-08-10 84 views
0

我正在写一个机器学习程序来识别黑白图像中的圆心。另外,图像生成脚本是在这里:生成Tensorflow的圆形图像预处理

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一起使用的正确方法是什么?如果有帮助,我打算使用卷积神经网络来识别中心。这可能是过度的,但在完成类似的,更复杂的任务之前,更多的是练习。

谢谢,任何意见表示赞赏。

回答