【发布时间】:2021-08-17 17:18:32
【问题描述】:
IMAGE_RES = 224
def format_image(image, label):
image = tf.image.resize(image, (IMAGE_RES, IMAGE_RES))/255.0
return image, label
BATCH_SIZE = 32
train_batches = train_dataset.map(format_image).batch(BATCH_SIZE).prefetch(1)
train_gray_batches = train_grey_dataset.map(format_image).batch(BATCH_SIZE).prefetch(1)
test_batches = test_dataset.map(format_image).batch(BATCH_SIZE).prefetch(1)
test_grey_batches = test_grey_dataset.map(format_image).batch(BATCH_SIZE).prefetch(1)
----------
threshold = 100.0
dropoutrate = 0.5
n_outchannels = 3
height, width = IMAGE_RES, IMAGE_RES
def max_norm_regularizer(threshold, axes=None, name="max_norm",
collection="max_norm"):
def max_norm(weights):
clipped = tf.clip_by_norm(weights, clip_norm=threshold, axes=axes)
clip_weights = tf.assign(weights, clipped, name=name)
tf.add_to_collection(collection, clip_weights)
return None # there is no regularization loss term
return max_norm
max_norm_reg = max_norm_regularizer(threshold=threshold)
clip_all_weights = tf.compat.v1.get_collection("max_norm")
----------
def leaky_relu(z,name=None):
return tf.maximum(0.5*z,z,name=name)
from functools import partial
he_init = tf.keras.initializers.VarianceScaling()
----------
X = tf.compat.v1.placeholder(shape=(None,width,height,2),dtype=tf.float32)
print(X)
training = tf.compat.v1.placeholder_with_default(False,shape=(),name='training')
X_drop = tf.keras.layers.Dropout(X,dropoutrate)
my_batch_norm_layer = partial(tf.keras.layers.BatchNormalization,training=training,momentum=0.9)
bn0 = my_batch_norm_layer(X_drop)
bn0_act = leaky_relu(bn0)
print(bn0_act)
此错误在我的程序中创建。我没有什么问题 明白要解决这个问题我搜索了很多次但没有解决这个问题 有问题吗?
Tensor("Placeholder_26:0", shape=(?, 224, 224, 2), dtype=float32)
TypeError Traceback (most recent call last) <ipython-input-64-adf525e2e2de> in <module>() 5 X_drop = tf.keras.layers.Dropout(X,dropoutrate) 6 my_batch_norm_layer = partial(tf.keras.layers.BatchNormalization,training=training,momentum=0.9) ----> 7 bn0 = my_batch_norm_layer(X_drop) 8 bn0_act = leaky_relu(bn0) 9 print(bn0_act) 4 frames /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/utils/generic_utils.py在 validate_kwargs(kwargs, allowed_kwargs, error_message) 1135 for kwarg in kwargs: 1136 如果 kwarg 不在 allowed_kwargs 中: -> 1137 引发类型错误(error_message,kwarg) 1138 第1139章
TypeError: ('Keyword argument not understood:', 'training')
【问题讨论】:
标签: python-3.x tensorflow keras neural-network