2017-12-16 14 views
0

를 반환는tf.shape()는 tensorflow의 API <code>tf.shape</code>에서 2 차원 텐서 아닌 1 차원

이 조작 입력의 형태를 나타내는 1-D 정수 텐서를 반환 말한다. 그러나

제가

features = { 
    'k_mask': tf.VarLenFeature(tf.int64), 
    'features': tf.VarLenFeature(tf.int64), 
    'labels': tf.FixedLenFeature([3], tf.int64), 
    'k_ids': tf.VarLenFeature(tf.int64) 
} 
parsed_features = tf.parse_single_example(example_proto, features) 
features_index = tf.sparse_tensor_to_dense(parsed_features['features']) 
print(sess.run(tf.shape(features_index))) 

전화 I는 2-D 정수 텐서 [[59]]의 결과를 얻는다. I이 정상적인 [1, 59] 텐서 생각

[[ 6217 5882 17223 17235 6008 3580 17233 6038 16340 6116 5458 5747 
    5957 5755 17238 5745 6030 6078 5786 4373 5888 16284 3574 3569 
    5811 6117 5748 17228 5810 5833 5823 5885 5986 6034 5756 6105 
    5832 6199 6087 5744 6037 5933 6095 5785 16290 6124 3559 5787 
    6111 3570 6109 17322 3840 5962 3566 16950 6006 3584 6011]] 

같이 feature_index 인쇄 될 수있다. 다음 코드를 시도해보십시오.

v1 = tf.constant([[4,3,1,7]]) 
print(sess.run(v1)) # [[4 3 1 7]] 
print(sess.run(tf.shape(v1))) # [1 4] 

예상대로 보입니다.

feature_index을 [59,1]의 모양으로 변환하고 싶습니다. 왜 리턴 타입이 2-d인지 그리고 텐서를 변환하는 방법을 아는 사람이 있습니까?

답변

0

마지막으로 다음과 같이 해결 :

features_index = tf.sparse_tensor_to_dense(parsed_features['features']) 
indices = tf.reshape(features_index, [tf.shape(features_index)[0], -1]) 

얻을 shape(indices) == [59,1]