2017-04-05 3 views
2

나는 크기가 [batch_size, w, h] 인 텐서의 이미지 묶음을 가지고 있습니다.tensorflow에서 tensor columns의 히스토그램을 만드는 방법

각 열의 값에 대한 히스토그램을 얻고 싶습니다.

이 내가 (하지만이 일괄 처리의 첫 번째 이미지에서만 작동하고 또한 매우 느린) 해낸 것입니다 :

global_hist = [] 
net = tf.squeeze(net) 
for i in range(batch_size): 
    for j in range(1024): 
     hist = tf.histogram_fixed_width(tf.slice(net,[i,0,j],[1,1024,1]), [0.0, 0.2, 0.4, 0.6, 0.8, 1.0], nbins=10) 
     global_hist[i].append(hist) 

이 작업을 수행 할 수있는 효율적인 방법이 있나요?

답변

0

괜찮 았어. 그래도 솔루션이 느려졌는데 (쓰레기통 가장자리를 고칠 수는 없지만) 누군가가이 유용함을 발견 할 수 있습니다.

nbins=10 
net = tf.squeeze(net) 
for i in range(batch_size): 
    local_hist = tf.expand_dims(tf.histogram_fixed_width(tf.slice(net,[i,0,0],[1,1024,1]), [0.0, 1.0], nbins=nbins, dtype=tf.float32),[-1]) 
    for j in range(1,1024): 
     hist = tf.histogram_fixed_width(tf.slice(net,[i,0,j],[1,1024,1]), [0.0, 1.0], nbins=nbins, dtype=tf.float32) 
     hist = tf.expand_dims(hist,[-1]) 
     local_hist = tf.concat(1, [local_hist, hist]) 
    if i==0: 
     global_hist = tf.expand_dims(local_hist, [0]) 
    else: 
     global_hist = tf.concat(0, [global_hist, tf.expand_dims(local_hist,[0])]) 

은 또한, 나는 매우 유용한 일이 링크를 발견 https://stackoverflow.com/questions/41764199/row-wise-histogram/41768777#41768777

관련 문제