尝试向我的神经网络添加更多隐藏层,以便我可以使用相同的学习率和动量等比较不同层的精度得分。
所以我有以下内容:
from nolearn.dbn import DBN
from sklearn.cross_validation import train_test_split
from sklearn.metrics import confusion_matrix
from sklearn.metrics import classification_report
from sklearn.metrics import accuracy_score
numFeat = 50 * 64
labs = ["BC", "FL", "PRO1", "PRO2", "RP", "SD"] # Defect types
hiddenAr = [numFeat, 6] # initial params for dbn
pos = len(hiddenAr) - 1
with open("all_defects.csv") as f:
reader = csv.reader(f)
for row in reader:
input = [int(x) for x in row[:numFeat]]
labels += [labs.index(row[-1])] # categorical labels in numerical form
data += [input]
X_train, X_test, y_train, y_test = train_test_split(
data, labels, test_size=0.25)
for i in range (0, layer):
hiddenAr.insert(pos, 300) # Add hidden layer
dbn = DBN(
hiddenAr,
# Learning rate of algorithm
learn_rates = 0.03,
# Decay of learn rate
learn_rate_decays=1,
# Iterations of training data (epochs)
epochs=10,
# Verbosity level
verbose=1,
momentum= 0.03,
use_re_lu=True
)
我在那里所做的只是每次将另外 300 个节点添加到另一个隐藏层。但是,当我出于某种原因将图层添加到其中时,它会吐出许多 npmat.py 错误。
这有明显的原因吗?我真的很想自动化它来添加隐藏层,这样我就可以轻松地生成图形和 csv 文件以进行评估。
错误发生在隐藏数组添加了第二层之后,即当 i = 1 时,然后对于之后添加的每一层:
npmat.py:433: RuntimeWarning: 在添加 target.numpy_array[:] = vec.numpy_array + self.numpy_array 中遇到无效值
RuntimeWarning:在 less target.numpy_array[:] = self.numpy_array < val 中遇到无效值
RuntimeWarning:在更大的范围内遇到无效值
npmat.py:969:RuntimeWarning:在乘法中遇到无效值
数据: https ://drive.google.com/file/d/0B12vhoNivII6My1GQ3E3T3JxQm8/view?usp=sharing