def applySoftMax( inputSample, inputSampleShape, numClasses, softmaxTemperature):
inputSampleReshaped = inputSample.dimshuffle(0, 2, 3, 4, 1)
inputSampleFlattened = inputSampleReshaped.flatten(1)
numClassifiedVoxels = inputSampleShape[2]*inputSampleShape[3]*inputSampleShape[4]
firstDimOfinputSample2d = inputSampleShape[0]*numClassifiedVoxels
inputSample2d = inputSampleFlattened.reshape((firstDimOfinputSample2d, numClasses))
# Predicted probability per class.
p_y_given_x_2d = T.nnet.softmax(inputSample2d/softmaxTemperature)
p_y_given_x_class = p_y_given_x_2d.reshape((inputSampleShape[0],
inputSampleShape[2],
inputSampleShape[3],
inputSampleShape[4],
inputSampleShape[1]))
p_y_given_x = p_y_given_x_class.dimshuffle(0,4,1,2,3)
y_pred = T.argmax(p_y_given_x, axis=1)
return ( p_y_given_x, y_pred )
# ----------------- Apply Bias to feat maps ---------------#
评论列表
文章目录