【问题标题】:TypeError: relu() missing 1 required positional argument: 'x'类型错误:relu() 缺少 1 个必需的位置参数:'x'
【发布时间】:2020-02-09 18:50:35
【问题描述】:

我收到了这个错误,但我不知道为什么会这样。任何人都帮帮我。

import warnings
warnings.filterwarnings('ignore',category=FutureWarning)
import tensorflow as tf
import keras
from keras.layers.convolutional import Conv2D, AtrousConvolution2D
from keras.layers import Activation, Dense, Input, Conv2DTranspose, Dense, Flatten
from keras.layers import Dropout, Concatenate, BatchNormalization, Reshape
from keras.layers.advanced_activations import LeakyReLU
from keras.models import Model, model_from_json
from keras.optimizers import Adam
from keras.layers.convolutional import UpSampling2D
import keras.backend as K
from keras.activations import relu


def g_build_conv(layer_input, filter_size, kernel_size=4, strides=2, activation='leakyrelu', 
    dropout_rate=g_dropout, norm='inst', dilation=1):
    c = AtrousConvolution2D(filter_size, kernel_size=kernel_size, strides=strides,atrous_rate= 
        (dilation,dilation), padding='same')(layer_input)
    if activation == 'leakyrelu':
        c = relu()(c)
    if dropout_rate:
        c = Dropout(dropout_rate)(c)
    if norm == 'inst':
        c = InstanceNormalization()(c)
    return c

警告(来自警告模块):文件 "C:\Users\xyz\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\legacy\layers.py", 第 762 行 warnings.warn('The AtrousConvolution2D layer ' UserWarning: The AtrousConvolution2D layer has been deprecated. 改用 带有dilation_rate 参数的Conv2D 层。回溯(最 最近通话最后):文件“D:\Image Outpaining\outpaint.py”,第 146 行, 在 GEN = build_generator() 文件“D:\Image Outpaining\outpaint.py”,第 120 行,在 build_generator g1 = g_build_conv(g_input, 64, 5, strides=1) 文件“D:\Image Outpaining\outpaint.py”,第 102 行,在 g_build_conv c = relu()(c) 类型错误:relu() 缺少 1 个必需的位置参数:'x'

【问题讨论】:

    标签: keras python-3.5 keras-layer relu


    【解决方案1】:

    keras.activations.relu 是一个函数,而不是一个层,所以你错误地调用了它。要将 ReLu 添加为层,请执行以下操作:

    from keras.layers import Activation
    
    if activation == 'leakyrelu':
        c = Activation("relu")(c)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 2018-09-12
      • 2021-08-05
      • 2021-07-06
      • 2021-08-05
      相关资源
      最近更新 更多