Iny*_*Kim 7 python python-3.x deep-learning ensemble-learning keras
我训练了两个独立的模型
我想要
not-related和good/normal/bad。我需要他们分开。我需要的一些伪代码
# Output of modelA will be a vector I presume `(1, None)` where `None` is batch
def ModelC.predict(input):
outputA = ModelA(input)
if outputA == 'not-related':
return outputA
return ModelB(outputA)
Run Code Online (Sandbox Code Playgroud)
我不知道如何if在模型推理中包含逻辑。我怎样才能做到这一点?
只需定义您自己的模型即可。我很惊讶你的其他模型输出字符串而不是数字,但如果没有更多信息,这就是我能给你的全部信息,所以我假设模型 A 的输出是一个字符串。
import tensorflow as tf
class ModelC(tf.keras.Model):
def __init__(self, A, B):
super(ModelC, self).__init__()
self.A = A
self.B = B
def call(self, inputs, training=False):
x = self.A(inputs, training)
if x == 'not-related':
return x
return self.B(inputs, training)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
123 次 |
| 最近记录: |