0
import tensorflow as tf
import keras
from keras import backend as K
from keras.layers.convolutional import MaxPooling2D,Conv2D
#使うレイヤーを選択
from keras.layers import Input,Dense, Activation, Multiply,Concatenate,Lambda,LeakyReLU
from keras.models import Model
from keras import regularizers            #レギュラーライザー
from keras.constraints import max_norm    #重みとかを2以上にしない(たぶん)
from keras.optimizers import Adam         #アダムを使用
import time
from keras.utils import plot_model
from collections import deque



class QNetwork :
    def __init__(self,learning_rate, state_size, action_size):
        self.inputs = Input(shape=(statesize[0],statesize[1],statesize[2],))

        self.a=Conv2D(32,kernel_size=(3,3),strides=1,padding='same',activation=LeakyReLU(alpha=0.01),
                      use_bias=True,kernel_initializer='he_normal',bias_initializer='zeros',kernel_constraint=max_norm(2.),
                      bias_constraint=max_norm(2.))(self.inputs)#aaaaaaa

        self.a=MaxPooling2D(pool_size=(2, 2))

        self.a=Conv2D(64,kernel_size=(3, 3), padding='same', data_format=None, dilation_rate=(1, 1),activation=LeakyReLU(alpha=0.01),
                      use_bias=True,kernel_initializer='he_normal',bias_initializer='zeros',kernel_constraint=max_norm(2.),
                      bias_constraint=max_norm(2.))(self.a)
        self.a=MaxPooling2D(pool_size=(2, 2))(self.a)#vavavava

        self.a=Conv2D(128,kernel_size=(3, 3), padding='same', data_format=None, dilation_rate=(1, 1),activation=LeakyReLU(alpha=0.01),
                      use_bias=True,kernel_initializer='he_normal',bias_initializer='zeros',kernel_constraint=max_norm(2.),
                      bias_constraint=max_norm(2.))(self.a)
        self.a=MaxPooling2D(pool_size=(2, 2))(self.a)


        self.a=Flatten()(self.a)


        self.a=Dense(250,activation='relu',
                     use_bias=True,kernel_initializer='he_normal',bias_initializer='zeros',kernel_constraint=max_norm(2.),
                     bias_constraint=max_norm(2.))(self.a)
        self.a=Dense(250,activation='relu',
                     use_bias=True,kernel_initializer='he_normal',bias_initializer='zeros',kernel_constraint=max_norm(2.),
                     bias_constraint=max_norm(2.))(self.a)


        self.v=Dense(1,      
                     use_bias=True,kernel_initializer='he_normal',bias_initializer='zeros',kernel_constraint=max_norm(2.),
                     bias_constraint=max_norm(2.))(self.v)

        self.dv=Dense(500,activation='relu'
                     ,use_bias=True,kernel_initializer='he_normal',bias_initializer='zeros',kernel_constraint=max_norm(2.),
                     bias_constraint=max_norm(2.))(self.a)   
        self.dv=Dense(action_size
                     ,use_bias=True,kernel_initializer='he_normal',bias_initializer='zeros',kernel_constraint=max_norm(2.),
                     bias_constraint=max_norm(2.))(self.dv)

        self.a = Concatenate()([self.v,self.dv])
        self.a = Lambda(lambda a: K.expand_dims(a[:, 0], -1) + a[:, 1:] - K.mean(a[:, 1:], axis=1, keepdims=True), 
                        output_shape=(action_size,))(self.a)

        self.adm = Adam(lr=learning_rate,beta_1=0.9, beta_2=0.999, amsgrad=False)
        self.model = Model(inputs=self.inputs, outputs=self.a)
        self.model.compile(loss=huberloss, optimizer=self.adm,metrics=['accuracy'])


learning_rate = 0.00001
action_size=2 #モデルのoutput
statesize=[400,400,3]   #モデルのinput

mainQN = QNetwork(learning_rate=learning_rate,state_size=statesize,action_size=action_size)  # メインQネットワーク
targetQN = QNetwork(learning_rate=learning_rate,state_size=statesize,action_size=action_size)  # 価値計算Qネットワーク
2
  • コードの一部やそれ以外の情報がうまく乗せれないのでコメントで追記  self.a=Conv2D(64,kernel_size=(3, 3), padding='same', data_format=None, dilation_rate=(1, 1),activation=LeakyReLU(alpha=0.01), use_bias=True,kernel_initializer='he_normal',bias_initializer='zeros',kernel_constraint=max_norm(2.), bias_constraint=max_norm(2.))(self.a) の のところでエラーが出ます(3層目)
    –  flan
    Commented 2020年5月3日 14:01
  • エラー内容は Layer conv2d_23 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.pooling.MaxPooling2D'>. Full input: [<keras.layers.pooling.MaxPooling2D object at 0x00000212F1655438>]. All inputs to the layer should be tensors.
    –  flan
    Commented 2020年5月3日 14:01

0

この質問に回答するには、ログインする必要があります。

のタグが付いた他の質問を参照する。