我正在尝试使用ONNX model zoo中的ResNet-50模型并将其加载并训练在CNTK中以进行图像分类任务。使我困惑的第一件事是,在此模型中,批处理轴(不确定它的正式名称是什么,动态轴?)设置为1:
那是为什么?难道不是简单的[3x224x224]?例如,在this model中,输入看起来像这样:
要加载模型并使用自己的Dense层,请使用以下代码:
WITH CTE AS(
SELECT *,
ROW_NUMBER() OVER( PARTITION BY clientId ORDER BY ProcDate) rn
FROM ProcJoins
WHERE ProcDesc NOT LIKE 'POC%'
)
SELECT c.clientId,
c.ProcDate,
c.ProcDesc,
COUNT(*)
FROM CTE c
LEFT JOIN CTE n ON c.ClientId = n.clientId
AND c.rn = n.rn-1
JOIN ProcJoins p ON c.ClientId = p.clientId
AND c.ProcDate <= p.ProcDate
AND ISNULL(n.ProcDate, '99991231') > p.ProcDate
WHERE p.ProcDesc LIKE 'POC%'
GROUP BY c.clientId,
c.ProcDate,
c.ProcDesc
ORDER BY c.ProcDate;
为了训练,我使用(缩短):
def create_model(num_classes, input_features, freeze=False):
base_model = load_model("restnet-50.onnx", format=ModelFormat.ONNX)
feature_node = find_by_name(base_model, "gpu_0/data_0")
last_node = find_by_uid(base_model, "Reshape2959")
substitutions = {
feature_node : placeholder(name='new_input')
}
cloned_layers = last_node.clone(CloneMethod.clone, substitutions)
cloned_out = cloned_layers(input_features)
z = Dense(num_classes, activation=softmax, name="prediction") (cloned_out)
return z
X_current是单个图像,y_current是相应的类标签,都被编码为具有以下形状的numpy数组
# datasets = list of classes
feature = input_variable(shape=(1, 3, 224, 224))
label = input_variable(shape=(1,3))
model = create_model(len(datasets), feature)
loss = cross_entropy_with_softmax(model, label)
# some definitions for learner, epochs, ProgressPrinters missing
for epoch in range(epochs):
loss.train((X_current,y_current), parameter_learners=[learner], callbacks=[progress_printer])
当我尝试训练模型时,我会得到
“ ValueError:ToBatchAxis7504 ToBatchAxisNode操作只能在没有小批量数据的情况下对张量进行操作(无布局)”
这是怎么了?