layerOperations.py 文件源码

python
阅读 41 收藏 0 点赞 0 评论 0

项目:LiviaNET 作者: josedolz 项目源码 文件源码
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 ---------------#
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号