3

다음과 같은 방법으로 네트워크 계층에 가우스 노이즈를 추가하려고합니다.Tensorflow의 가우스 노이즈 추가

ValueError: Cannot convert a partially known TensorShape to a Tensor: (?, 2600, 2000, 1)

내 minibatches 때로는 서로 다른 크기의 할 필요가 있으므로 input_layer 텐서의 크기는 실행 시간까지 알 수 없습니다 :

def Gaussian_noise_layer(input_layer, std): 
    noise = tf.random_normal(shape = input_layer.get_shape(), mean = 0.0, stddev = std, dtype = tf.float32) 
    return input_layer + noise 

나는 오류를 받고 있어요.

정확하게 이해하면 Cannot convert a partially converted tensor in TensorFlow에 답변 한 사람이 tf.shape (input_layer)로 모양을 설정하도록 제안했습니다.

ValueError: dims of shape must be known but is None

때까지 알 수없는 형태의 입력 레이어에 가우스 노이즈를 추가 내 목표를 달성하는 올바른 방법은 무엇입니까 : 그 시끄러운 레이어에 길쌈 레이어를 적용하려고 때 다음, 나는 또 다른 오류 실행 시간?

답변

9

는 동적으로 예를 들어 tf.shape()

를 사용할 필요가 알 수없는 크기로 텐서의 모양을 얻으려면

import tensorflow as tf 
import numpy as np 


def gaussian_noise_layer(input_layer, std): 
    noise = tf.random_normal(shape=tf.shape(input_layer), mean=0.0, stddev=std, dtype=tf.float32) 
    return input_layer + noise 


inp = tf.placeholder(tf.float32, shape=[None, 8], name='input') 
noise = gaussian_noise_layer(inp, .2) 
noise.eval(session=tf.Session(), feed_dict={inp: np.zeros((4, 8))})