小编Dav*_* S.的帖子

将神经网络输出限制为受过训练的课程的子集

是否有可能将向量传递到经过训练的神经网络,以便它仅从经过训练的识别类的子集中进行选择。例如,我的网络经过训练可以识别数字和字母,但是我知道接下来要运行的图像将不包含小写字母(例如序列号的图像)。然后我给它传递一个向量,告诉它不要猜测任何小写字母。由于类是互斥的,因此网络以softmax函数结尾。以下只是我想尝试的示例,但没有一个真正起作用。

import numpy as np

def softmax(arr):
    return np.exp(arr)/np.exp(arr).sum()

#Stand ins for previous layer/NN output and vector of allowed answers.
output = np.array([ 0.15885351,0.94527385,0.33977026,-0.27237907,0.32012873,
       0.44839673,-0.52375875,-0.99423903,-0.06391236,0.82529586])
restrictions = np.array([1,1,0,0,1,1,1,0,1,1])

#Ideas -----

'''First: Multilpy restricted before sending it through softmax.
I stupidly tried this one.'''
results = softmax(output*restrictions)

'''Second: Multiply the results of the softmax by the restrictions.'''
results = softmax(output)
results = results*restrictions

'''Third: Remove invalid entries before calculating the softmax.'''
result = output*restrictions
result[result != 0] = softmax(result[result != 0]) …
Run Code Online (Sandbox Code Playgroud)

python neural-network keras tensorflow

7
推荐指数
1
解决办法
480
查看次数

标签 统计

keras ×1

neural-network ×1

python ×1

tensorflow ×1