FailedPreconditionError:尝试使用未初始化的值lambda / Variable

时间:2019-06-12 01:50:43

标签: python tensorflow unity3d-unet

我一直在尝试执行UNET CNN代码,但遇到相同的错误: FailedPreconditionError:尝试使用未初始化的值lambda / Variable

当我调用函数时出现问题:

model.fit(x_train,y_train,batch_size = 16,epochs = 1000,shuffle = True,validation_data = [x_val,y_val])

我已经尝试过使用tf.global_variables_initializer()初始化变量,但问题仍然存在

我的tensorflow-gpu版本: '1.13.1'

我的python版本: '3.7.3'

图形卡: 泰坦RTX

def U_Net(activation='relu', ft_root=64, batch_norm=True):

        inputs = Input((None, None, None, 1))
        x = inputs

        # Dictionary for long connections
        var_dict = {}
        # Down sampling

        for i in range(self.n_layers):
            out_channel= 2**i * ft_root
            # Convolutions
            conv1 = Conv3D(out_channel, kernel_size=3, padding='same')(x) 
            if batch_norm:
                conv1 = BatchNormalization()(conv1)
            act1 = Activation(activation)(conv1)

            conv2 = Conv3D(out_channel, kernel_size=3, padding='same')(act1) # deuxieme couche de convolution
            if batch_norm:
                conv2 = BatchNormalization()(conv2)
            act2 = Activation(activation)(conv2)
            # Max pooling
            if i < self.n_layers - 1:
                var_dict[str(i)] = act2
                x = MaxPooling3D(padding='same')(act2)
            else:
                x = act2

        # Upsampling

        for i in range(self.n_layers-2, -1, -1):
            out_channel = 2**(i)*ft_root
            # Convolution transposed
            upconv = Conv3DTranspose(out_channel, kernel_size=2, strides=2, use_bias=False)(x) # upsampling
            upconv_ = Lambda(CroppingLayer)([upconv, var_dict[str(i)]])
            uplong = Add()([upconv_, var_dict[str(i)]]) # skip connection

            # Convolutions
            conv1 = Conv3D(out_channel, kernel_size=3, padding='same')(uplong)
            if batch_norm:
                conv1 = BatchNormalization()(conv1)
            act1 = Activation(activation)(conv1)

            conv2 = Conv3D(out_channel, kernel_size=3, padding='same')(act1)
            if batch_norm:
                conv2 = BatchNormalization()(conv2)
            x = Activation(activation)(conv2)

        # Final convolution
        output = Conv3D(1, kernel_size=1, padding='same', activation='sigmoid')(x)
        return Model(inputs, output, name='U-Net')



def dice_loss(labels, logits):
        eps = 1e-5
        pred = K.flatten(logits) 
        lab = K.flatten(labels)
        intersection = K.sum(pred*lab)
        dice_0 = (2*intersection + eps) / (K.sum(pred) + K.sum(lab) + eps)
        return 1 - dice_0


tf.global_variables_initializer()
model.fit(x_train, y_train, batch_size=16, epochs=1000, shuffle=True, validation_data=[x_val, y_val])

我希望培训开始进行;但确切的输出是:

退出中的文件“ /home/derf/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/errors_impl.py”,第528行     c_api.TF_GetCode(self.status.status)) FailedPreconditionError:尝试使用未初始化的值lambda / Variable      [[{{node lambda / Variable / read}}]]      [[{{node loss / mul}}]]

0 个答案:

没有答案