Keras 2.0版本運行demo出錯:html
d:\program\python3\lib\site-packages\ipykernel_launcher.py:8: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(32, (3, 3), activation="relu")`
使用Keras時用到了卷積層Convolution2D( )以及Model.fit( ):python
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
Model.fit(x_train, x_train, nb_epoch=10, batch_size=256, shuffle=True, validation_data=(x_test, x_test))
遇到了以下錯誤:git
UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(1, (3, 3), padding="same", activation="sigmoid")`
decoded = Convolution2D(1, 3, 3, activation='sigmoid', border_mode='same')(x)
在查看了github上的Keras 2.0發行說明後,發現這是從Keras 1到Keras 2發生的變化.github
此處涉及到的有:
Convolution* 層被從新命名 Conv* ;
border_mode - > padding ;
nb_epoch - > epochs;
kernel_size能夠設置爲一個整數,例如Conv2D(10, 3)至關於Conv2D(10, (3, 3));shell
所以,函數
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
Model.fit(x_train, x_train, nb_epoch=10, batch_size=256, shuffle=True, validation_data=(x_test, x_test))post
改成:url
x = Conv2D(8, 3, activation='relu', padding='same')(x)
Model.fit(x_train, x_train, epochs=10, batch_size=256, shuffle=True, validation_data=(x_test, x_test))spa
修正後版本:.net
from keras.models import *
from keras.layers import *
import sys
input_tensor = Input((height, width, 3))
x = input_tensor
for i in range(4):
x = Conv2D(32*2**i, 3, activation='relu')(x)
x = Conv2D(32*2**i, 3, activation='relu')(x)
x = MaxPooling2D((2, 2))(x)
x = Flatten()(x)
x = Dropout(0.25)(x)
x = [Dense(n_class, activation='softmax', name='c%d'%(i+1))(x) for i in range(4)]
model = Model(inputs=input_tensor, outputs=x)
model.compile(loss='categorical_crossentropy',
optimizer='adadelta',
metrics=['accuracy'])
其餘更多變化參見:Keras 2.0發行說明
原文:https://blog.csdn.net/akadiao/article/details/80405766
ImportError: No module named 'keras.utils.visualize_util'
一、Q:ImportError: No module named visualize_util
A:自從2017年以後,visualize_util 變成vis_utils, 而且plot函數從新命名成plot_model.
You will have to either fix the code manually, or downgrade Keras.
By looking at the commit history of that module, you can see that it was renamed on February 28, 2017 from visualize_util
to vis_utils
. The plot
function was also renamed to plot_model
.
python 版本問題
Traceback (most recent call last):
File 「<pyshell#32>」, line 1, in <module>
f.next()
AttributeError: ‘generator’ object has no attribute ‘next’
緣由是在python 3.x中 generator(有yield關鍵字的函數則會被識別爲generator函數)中的next變爲__next__了,next是python 3.x之前版本中的方法
修改成下面這樣運行正常f=fab(5)f.__next__()