2017-08-31 2 views
0

こんにちは、イメージとそれらのホットアレイラベルのためのtfrecordを作成したいと思います。イメージのためにそれを達成することができますが、ラベルではありません。これはSOF link、同じエラーが表示されます。下は私のコードです。イメージラベルのテンソルフローを作成できません

def _int64_feature(value): 
return tf.train.Feature(int64_list=tf.train.Int64List(value=[value])) 


def _bytes_feature(value): 
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value])) 


for i in range(len(train_addrs)): 

    print('reading image no {0} : and image address {1}'.format(i,train_addrs[i])) 

    img = load_image(train_addrs[i])#loading the preprocessed image 

    label = train_labels[i]#loading associated one-hot array 

    print('label is ',label) #array([0, 1]) of type uint8 ,I tried with int64,int32 also;but no use 

    feature = {'train/label':_int64_feature(label), 
      'train/image':_bytes_feature(tf.compat.as_bytes(img.tostring())) #this part works 
      }  


    example = tf.train.Example(features=tf.train.Features(feature=feature)) 

    serToString = example.SerializeToString() 

    writer.write(serToString) 

このコードを実行すると、次のエラーが表示されます。

TypeError: array([0, 1]) has type <type 'numpy.ndarray'>, but expected one of: (<type 'int'>, <type 'long'>) 

イムはわからない私は間違って行くのですか?すべてのヘルプは本当に参考になります。

答えて

1

あなたは_int64_featureとしてラベルを定義しているので、あなたがラベルにint型を使用する必要はありませnumpy array

label = train_labels[i]#loading associated one-hot array 
    label = np.argmax(label) 

データを読みながらあなたはone_hot形式に変換することができます。

リストとして渡す場合は、あなたの関数定義を変更してください

def _int64_feature(value): 
    return tf.train.Feature(int64_list=tf.train.Int64List(value=value)) 
+0

返信ありがとうございました。しかし、上記のリンクでは、スティーブンはリストを通過しました。それは可能ですか? – george

+0

はい!あなたのためにあなたの関数を変更する必要があります、私の更新された答えを参照してください。 –

+0

ありがとうございます。トレーニングのためにテンソルフローのパイプラインにデータを入力する際のチュートリアルをお勧めしますか? – george

関連する問題