我正在写关于关于此处提供的答案的后续问题: Keras model.fit UnboundLocalError
@ivan_pozdeev提供的答案如下: 在engine / training.py中,
@IBDesignable
class Label: UILabel {
override func awakeFromNib() {
super.awakeFromNib()
config()
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
config()
}
func config() {
// Setup how you please, e.g. color = UIColor.black
}
}
应该是
elif data.__class__.__name__ == 'DataFrame':
# test if data is a DataFrame, without pandas installed
data = data.values
为了回应ivan_pozdeev的回答,我在training.py中做了建议的更改:我在代码的建议行中将'data'更改为'arrays'。但是,我仍然收到一条错误:
elif data.__class__.__name__ == 'DataFrame':
# test if data is a DataFrame, without pandas installed
arrays = data.values
复制并粘贴到下方,请查看我的数据的详细信息:
X_train形状:(83,600,800,3);
Y_train形状:(83,2);
X_test形状:(17,600,800,3);
Y_test形状:(17,2);
X_train和X_test是'numpy.ndarray。'
Y_train和Y_test是'pandas.core.frame.DataFrame。'
作为我的数据的简要描述,X_train和X_test是从png文件创建的:
File "/home/user/anaconda2/lib/python2.7/site-packages/keras/engine/training.py", line 1555, in fit
class_weight=class_weight,
File "/home/user/anaconda2/lib/python2.7/site-packages/keras/engine/training.py", line 1413, in _standardize_user_data
output_shapes,
File "/home/user/anaconda2/lib/python2.7/site-packages/keras/engine/training.py", line 126, in _standardize_input_data
# Make arrays at least 2D.
UnboundLocalError: local variable 'arrays' referenced before assignment
其中Xdataset随机分为X_train和X_test。
Ydataset是从csv文件中提取为pandas dataframe:
from PIL import Image
images = glob('*.png')
a = []
for k in range(0, 100):
image = images[k]
arr = np.array(Image.open(image).convert('RGB'))
a.append(arr)
new_a = np.stack(a, axis=0)
Xdataset = new_a
Ydataset随机分为Y_train和Y_test。 Ydataset有两列数字(float64)值,表示两个不同的参数值。
输入数据X_train和X_test被送入CNN。输出Y_train和Y_test由两列数值组成,即2个参数的回归预测值。
我是keras的新手。 我的问题是 - 除了@ ivan_pozdeev的回答,我还能做些什么来解决我得到的错误?我的建议将不胜感激。