|
参考该代码,使用lamba表达式,降低for循环导致的时间消耗。还有一种方式是直接计算出min_score所对应的outclass里的值,直接进行筛选,过滤得分较低的数值
- def scaleToInputSize2(outputClasses, numClasses):
- validCount = 0;
- output = numpy.zeros(shape=(2,NUM_RESULTS))
- tmp_shape = outputClasses.shape
- score_class = map(lambda x: expit(x), outputClasses.flatten())
- score_class = list(score_class)
- score_class = np.array(score_class)
- score_class = score_class.reshape(tmp_shape)
- for i in range(0, NUM_RESULTS):
- topClassScore = -1000.0
- topClassScoreIndex = -1
- for j in range(1, numClasses):
- score = score_class[i][j]
- if (score > topClassScore) :
- topClassScoreIndex = j
- topClassScore = score
- if (topClassScore >= MIN_SCORE):
- output[0][validCount] = i
- output[1][validCount] = topClassScoreIndex
- validCount += 1
- return validCount, output
|
|