keras - 类型错误:relu() 缺少 1 个必需的位置参数:'x'
问题描述
我收到了这个错误,我不知道为什么会这样。任何人都帮帮我。
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:该AtrousConvolution2D
层已被弃用。使用Conv2D
带有dilation_rate
参数的层。回溯(最近一次调用最后):文件“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.activations.relu
是一个函数,而不是一个层,所以你不正确地调用它。要将 ReLu 添加为层,请执行以下操作:
from keras.layers import Activation
if activation == 'leakyrelu':
c = Activation("relu")(c)
推荐阅读
- java - Retrofit + Gson 无法解析简单的 Map
- css - Angular 应用程序中所有页面的字体系列更改
- python - 为什么以下 Python 代码不删除列?
- xamarin.forms - Xamarin.Forms 仅在一个平台 (iOS) 上更改条目的占位符颜色和文本颜色
- azure - 在 ARM 模板中获取 Azure 存储 dacpac 文件
- python - 如何在 Python 3.7 中运行 manim 示例?
- php - 如果数组的元素与
- powershell - 使用 PowerShell 从数组中提取特定字符串
- javascript - '"openURL"' 类型的参数不能使用 Jest 分配给 'never' 类型的参数
- python - 如何处理页面中的不同元素(国家天气)以进行网页抓取