AttributeError: module 'keras.backend' has no attribute 'set_image_dim_ordering'
AttributeError: module 'keras.backend' has no attribute 'set_image_dim_ordering'
model = Sequential()
K.set_image_dim_ordering('th')
model.add(Convolution2D(30, 5, 5, border_mode= 'valid' , input_shape=(1, 10, 10),activation= 'relu' ))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Convolution2D(15, 3, 3, activation= 'relu' ))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(128, activation= 'relu' ))
model.add(Dense(50, activation= 'relu' ))
model.add(Dense(10, activation= 'softmax' ))
# Compile model
model.compile(loss= 'categorical_crossentropy' , optimizer= 'adam' , metrics=[ 'accuracy' ])
当我从 keras.backend
使用 set_image_dim_ordering()
时出现错误
这是错误报告:AttributeError: module 'keras.backend' has no attribute 'set_image_dim_ordering'
我的导入语句
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout
from keras.layers import Flatten
from keras.layers.convolutional import Convolution2D
from keras.layers.convolutional import MaxPooling2D
from sklearn.preprocessing import LabelEncoder,OneHotEncoder
from keras import backend as K
from subprocess import check_output
有几件事要看。这是一个 known issue 并针对版本 2.2.5 报告,但应该适用于 2.2.4 及之前的版本。
但是,无论如何您都应该停止使用此方法,因为它现在是遗留的并且已被 image_data_format: [code]
取代
keras.backend.image_data_format()
keras.backend.set_image_data_format(data_format)
它应该可以继续工作,但至少现在有一个错误。
编辑: 下面报告的海报不起作用或returns他们的代码有错误,尽管该方法似乎确实存在。
Some have reported that you may be able to access the method using K.common
but I haven't tested:
K.common.image_dim_ordering()
K.common.set_image_dim_ordering(dim_ordering)
尝试用 K.image_dim_ordering='th'
替换 K.set_image_dim_ordering('th')
。它对我有用。
我不确定,但主要问题与您使用的 keras 版本有关。
model = Sequential()
K.set_image_dim_ordering('th')
model.add(Convolution2D(30, 5, 5, border_mode= 'valid' , input_shape=(1, 10, 10),activation= 'relu' ))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Convolution2D(15, 3, 3, activation= 'relu' ))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(128, activation= 'relu' ))
model.add(Dense(50, activation= 'relu' ))
model.add(Dense(10, activation= 'softmax' ))
# Compile model
model.compile(loss= 'categorical_crossentropy' , optimizer= 'adam' , metrics=[ 'accuracy' ])
当我从 keras.backend
set_image_dim_ordering()
时出现错误
这是错误报告:AttributeError: module 'keras.backend' has no attribute 'set_image_dim_ordering'
我的导入语句
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout
from keras.layers import Flatten
from keras.layers.convolutional import Convolution2D
from keras.layers.convolutional import MaxPooling2D
from sklearn.preprocessing import LabelEncoder,OneHotEncoder
from keras import backend as K
from subprocess import check_output
有几件事要看。这是一个 known issue 并针对版本 2.2.5 报告,但应该适用于 2.2.4 及之前的版本。
但是,无论如何您都应该停止使用此方法,因为它现在是遗留的并且已被 image_data_format: [code]
取代keras.backend.image_data_format()
keras.backend.set_image_data_format(data_format)
它应该可以继续工作,但至少现在有一个错误。
编辑: 下面报告的海报不起作用或returns他们的代码有错误,尽管该方法似乎确实存在。
Some have reported that you may be able to access the method using
K.common
but I haven't tested:K.common.image_dim_ordering() K.common.set_image_dim_ordering(dim_ordering)
尝试用 K.image_dim_ordering='th'
替换 K.set_image_dim_ordering('th')
。它对我有用。
我不确定,但主要问题与您使用的 keras 版本有关。