如何输出标量变量作为Keras模型的输出?

时间:2019-04-12 11:06:28

标签: keras

例如,我想要类似的东西

模型(输入=某物,输出=标量)

在您想调试没有状态“ X”的情况下的模型/训练过程时,首先出现(生成)。因此,您仍然具有Y的batch_size。这就是您想要的。

我正在尝试这样的事情:

val mongoClient = MongoClient("uriString")
val db = mongoClient.getDatabase("databasename")
val collection = db.getCollection("collectionName")
var observableDoc = collection.find(equal("my_id", "12345")).first

observableDoc.subscribe(new Observer[T] {
  println(funcname + " : Inside observableStatus subscribe start")
  logger.info(funcname + " : Inside observableStatus subscribe start")

  override def onNext(result: T): Unit = {
    println(funcname + " onNext")
    logger.info(funcname + " onNext")
  }

  override def onError(e: Throwable): Unit = {
    println(funcname + " Failed")
    logger.info(funcname + " Failed")
  }

  override def onComplete(): Unit = {
    println(funcname + " Complete")
    logger.info(funcname + " Complete")
  }

  println(funcname + " : Inside observableStatus subscribe end")
  logger.info(funcname + " : Inside observableStatus subscribe end")
})

val awaitedR = Await.result(observableDoc.toFuture, Duration.Inf)

1 个答案:

答案 0 :(得分:0)

一种简单的方法是使用Keras的功能性API:Keras API docu

inputs = Input(shape=(784,))

# a layer instance is callable on a tensor, and returns a tensor
x = Dense(64, activation='relu')(inputs)
x = Dense(64, activation='relu')(x)
predictions = Dense(10, activation='softmax')(x)

v = 0.25 * x

# This creates a model that includes
# the Input layer and three Dense layers
model = Model(inputs=inputs, outputs=[predictions, v])