2016-06-24 2 views
0

내 데이터 구조에 배치된다 "잘못된 형식 목록"을 반환합니다. basepath을 입력으로 받아들이는 입력 파이프 라인을 만들고, image_oplabel_op을 생성하려고합니다. 이러한 예컨대, 나에게 (이미지, 라벨) 튜플을 줄 것이라고 평가 :평가 tf.py_func는()

image, label = session.run([image_op, label_op]) 

것은 나는 그것의 이미지 경로 봐야한다 주어진 이미지에 대한 레이블을 얻으려면. 하나의 간단한 해결책은 할 수 있습니다 :

label = int("good" in path) 

내가 (V0.9) 알고 있어요 tensorflow 이러한 문자열 작업에 대한 어떠한 지원도 없다, 그래서 같은 간단한 기능을 통해 tf.py_func 래퍼를 사용하는 생각 위. 그러나 같은 방법으로 레이블을 평가하는 동안 이미지 경로 op와 이미지 경로 op를 입력으로 사용하여 동일한 경로를 평가하려고 할 때 같은 오류가 발생합니다. 오류가 발생합니다. 나는 모두가 잘

label = session.run(data_reading_graph.label) 

을 실행하고 예상대로 내가 레이블을 얻는 경우에 지금

def get_label(path): 
    return int("good" in str(path)) 

class DataReadingGraph: 
    """ 
    Graph for reading images into a data queue. 
    """ 

    def __init__(self, base_path): 
     """ 
     Construct the queue 
     :param base_path: path to base directory that contains good images and bad images 
     subdirectories. They in turn can contain further subdirectories. 
     :return: 
     """ 

     # tf can't handle recursive files matching (as of version 0.9), so 
     # solve that with glob and just pass globbed paths to a constant 
     pattern = os.path.join(base_path, "**/*.jpg") 
     filenames = tf.constant(glob.glob(pattern, recursive=True)) 

     filename_queue = tf.train.string_input_producer(filenames, shuffle=True) 
     reader = tf.IdentityReader() 
     self.key, self.value = reader.read(filename_queue) 

     self.label = tf.py_func(get_label, [self.key], [tf.int64]) 

:

여기 내 파이썬 기능과 TF 그래프 코드입니다. 내가 대신

key, label = session.run([data_reading_graph.key, data_reading_graph.label]) 

을 실행하면, 나는 '왜 내가 할 수있는

<class 'TypeError'> 
Fetch argument [<tf.Tensor 'PyFunc:0' shape=<unknown> dtype=int64>] of [<tf.Tensor 'PyFunc:0' shape=<unknown> dtype=int64>] has invalid type <class 'list'>, must be a string or Tensor. (Can not convert a list into a Tensor or Operation.) 

난 정말 비록 그것이 안 목록으로 변환있어 무엇을, 여기에 무엇이 잘못되었는지 이해하지 얻을 키 op와 레이블 op를 동일한 session.run()에서 평가하십시오.

내가하고 시도 할 수는 TF 그래프를 시작하기 전에 순수 파이썬 코드에서 추출 레이블, 그러나 문제는 남아있다 - 왜 py_func과 같은 session.run()

답변

1

tf.py_func 리턴한다 목록의에서 입력을 평가할 수 없습니다 텐서.

당신은 단지 self.label = self.label[0]을 얻어야한다 :

filename_queue = tf.train.string_input_producer(filenames, shuffle=True) 
    reader = tf.IdentityReader() 
    self.key, self.value = reader.read(filename_queue) 

    self.label = tf.py_func(get_label, [self.key], [tf.int64])[0] 
+0

오 사랑을, 당신은 완전히 옳다. 나는 지금 바보 같이 느껴져. 고마워. – Puchatek

+0

처음에 나는 그것이'tf.py_func'에있는 진짜 버그라고 생각했으나 아무런 문제가 없었습니다. :) –