2017-09-28 5 views
3

TFRecord와 함께 작동하는 tensorflow 프로그램이 있는데 tf.contrib.data.TFRecordDataset을 사용하여 데이터를 읽으려고하지만 예제를 구문 분석하려고 할 때 예외가 발생합니다. "TypeError : 변환하지 못했습니다. 텐서 흐름에Sparse Tensor in tensorflow DataSets

def _parse_function(example_proto): 
    features = {"var_len_feature": tf.VarLenFeature(tf.float32), 
       "FixedLenFeature": tf.FixedLenFeature([10], tf.int64), 
       "label": tf.FixedLenFeature((), tf.int32default_value=0)} 

parsed_features = tf.parse_single_example(example_proto, features) 
return parsed_features["image"], parsed_features["label"] 

filenames = ["/var/data/file1.tfrecord", "/var/data/file2.tfrecord"] 
dataset = tf.contrib.data.TFRecordDataset(filenames) 
dataset = dataset.map(_parse_function) 
+0

여기에 대한 업데이트가 있습니까? 대답이 –

+0

인 @AdamSnaider 예를 아는 것이 유용 할 것입니다. 1.5에서 지원됩니다. –

답변

0

자습서 guide 다른 들여 쓰기가 프로그래밍 : 만

코드로 시도 할 때 유형의 객체는 " 을 텐서합니다.

# Transforms a scalar string `example_proto` into a pair of a scalar string and 
# a scalar integer, representing an image and its label, respectively. 
def _parse_function(example_proto): 
    features = {"image": tf.FixedLenFeature((), tf.string, default_value=""), 
       "label": tf.FixedLenFeature((), tf.int32, default_value=0)} 
    parsed_features = tf.parse_single_example(example_proto, features) 
    return parsed_features["image"], parsed_features["label"] 

# Creates a dataset that reads all of the examples from two files, and extracts 
# the image and label features. 
filenames = ["/var/data/file1.tfrecord", "/var/data/file2.tfrecord"] 
dataset = tf.contrib.data.TFRecordDataset(filenames) 
dataset = dataset.map(_parse_function) 

잘못된 들여 쓰기로 인해 TypeError가 발생하여 pyton 해석기에서 원하지 않는 제어 흐름을 처리 할 수 ​​있습니다.

+0

들여 쓰기와 관련이 없습니다. FixedLenFeature에서는 작동하지만 VarLenFeature에서는 작동하지 않습니다. 들여 쓰기는 내가 stackOverFlow에 대해서만 만든 샘플에 있습니다. –

0

tf.VarLenFeature가 SparseTensor를 만듭니다. 스파 스 센서가 미니 배치와 관련이있는 경우가 대부분입니다. 아래처럼해볼 수 있습니까?

세트 = tf.contrib.data.TFRecordDataset (파일명)

세트 = dataset.batch (BATCH_SIZE = 32)

세트 = dataset.map (_parse_function)

+0

시도했지만 작동하지 않았습니다. –