Keras 2.0版本运行

Keras 2.0版本运行demo出错:

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( ):

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))

遇到了如下错误:

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发生的变化.

此处涉及到的有:
Convolution* 层被重新命名 Conv* ;
border_mode - > padding ;
nb_epoch - > epochs;
kernel_size可以设置为一个整数,例如Conv2D(10, 3)相当于Conv2D(10, (3, 3));

因此,

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))


改为:

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))

 

修正后版本:

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'

1、Q:ImportError: No module named visualize_util

A:自从2017年之后,visualize_util 变成vis_utils, 并且plot函数重新命名成plot_model.

down vote accepted

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__()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值