我正在创建一个CNN鉴别器模型来验证gan的音频。它取自gan的发生器部分的输出张量。但由于某些原因,当使用带有来自生成器的音频张量的编译模型时,我得到了这个甚至没有指定行号的奇怪错误。
代码:
<header class="primary-header">
<h5 class="logo-name">Roger Anderson</h5>
<nav class="nav">
<ul>
<li><a href="about.html">about</a></li>
<!--
-->
<li><a href="portfolio.html">portfolio</a></li>
<!--
-->
<li><a href="contact.html">contact</a></li>
</ul>
</nav>
</header>
错误:
def build_audio_discriminator(audio_shape, num_classes):
model = Sequential()
model.add(Conv1D(32, kernel_size=(2), padding="same", input_shape=audio_shape))
model.add(MaxPooling1D(pool_size=(2)))
model.add(Dropout(0.25))
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(128))
model.summary()
audio_shape_ = (None, audio_shape[1])
audio = Input(shape=audio_shape_)
# Extract feature representation
features = model(audio)
# Determine validity and label of the image
validity = Dense(1, activation="sigmoid")(features)
label = Dense(num_classes+1, activation="softmax")(features)
return Model(audio, [validity, label])
# Build and compile the discriminator
#audio_shape: (31, 214161), num_classes: 1
audio_discriminator = build_audio_discriminator(audio_shape, num_classes)
audio_discriminator.compile(loss=losses, optimizer=optimizer, metrics=['accuracy'])
# audio: Tensor("model_4/sequential_4/activation_4/Softmax:0", shape=(?, 214161), dtype=float32)
audio_valid, audio_target_label = audio_discriminator(audio)
答案 0 :(得分:0)
Solution was to reshape input Tensor to proper Conv1D input shape: (-1, 214161, 1)
def post_list(request, tag_slug=None):
object_list = Post.published.all()
tag = None
if tag_slug:
tag = get_object_or_404(Tag, slug=tag_slug)
object_list = object_list.filter(tags__in=[tag])
paginator = Paginator(object_list, 3) # 3 posts in each page
page = request.GET.get('page')
try:
posts = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer deliver the first page
posts = paginator.page(1)
except EmptyPage:
# If page is out of range deliver last page of results
posts = paginator.page(paginator.num_pages)
return render(request, 'blog.html', {'page': page, 'posts': posts, 'tag': tag})
The solution shown above lets you run into a problem though, because the object returned by tf.reshape is not a Keras tensor but a standard tensor without _keras_history flag. My recommendation is to add:
key << { myDriver.myMap.keySet() }()
instead the solution above to your model.