亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 keras 功能模型時出現類型錯誤

使用 keras 功能模型時出現類型錯誤

楊__羊羊 2021-09-28 17:03:46
我使用 Keras 函數式 API(keras 2.2 版)來定義模型,但是當我嘗試將數據擬合到模型時,我得到了一些錯誤。我目前使用的是 python 2.7,代碼在 Ubuntu 18.04 上運行。以下是模型的代碼:class Model:    def __init__(self, config):        self.hidden_layers = config["hidden_layers"]        self.loss = config["loss"]        self.optimizer = config["optimizer"]        self.batch_normalization = config["batch_normalization"]        self.model = self._build_model()    def _build_model(self):        input = Input(shape=(32,))        hidden_layers = []        if self.batch_normalization:            hidden_layers.append(Dense(self.hidden_layers[0], bias_initializer= Orthogonal)(input))            hidden_layers.append(BatchNormalization()(hidden_layers[-1]))            hidden_layers.append(Activation("relu")(hidden_layers[-1]))        else:            hidden_layers.append(Dense(self.hidden_layers[0], bias_initializer= Orthogonal, activation='relu')(input))        for i in self.hidden_layers[1:]:            if self.batch_normalization:                hidden_layers.append(Dense(i, bias_initializer= Orthogonal)(hidden_layers[-1]))                hidden_layers.append(BatchNormalization()(hidden_layers[-1]))                hidden_layers.append(Activation("relu")(hidden_layers[-1]))            else:                hidden_layers.append(Dense(i, bias_initializer= Orthogonal, activation='relu')(hidden_layers[-1]))        output_layer = Dense(2, activation="softmax")(hidden_layers[-1])        model = Model(input= input, output= output_layer)        model.compile(optimizer=self.optimizer, loss=self.loss, metrics=["accuracy"])        return model我真的不明白這個 TypeError 是什么。我不確定如何更改我的模型定義以避免此錯誤。
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 267 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號