ไม่สามารถแปลง 1.0 เป็น EagerTensor ของ dtype int32

ฉันกำลังพยายามใช้ keras เพื่อสร้าง cnn และใช้ SVM หลังจากเลเยอร์หนาแน่นของ cnn เป็นตัวแยกประเภท ดังนั้นฉันจึงพยายามได้ผลลัพธ์หลังจากเลเยอร์ที่มีความหนาแน่นสูง

model = Sequential()
model.add(Conv1D(filters=64, kernel_size=(5), input_shape=(12,800), strides=2, padding='valid', activation='relu'))
model.add(AveragePooling1D(pool_size=2,strides=2,padding='same'))

model.add(Flatten())
model.add(Dense(7 ,activation='softmax'))

model.compile(optimizer='adam',loss='mean_squared_error',metrics=['accuracy'])
model.summary()

รหัสของฉันสำหรับรับเอาต์พุตหลังจากเลเยอร์หนาแน่น

inp = model.input                                           # input placeholder
outputs = [layer.output for layer in model.layers]          # all layer outputs
functor = k.function([inp, k.learning_phase()], outputs )   # evaluation function

# Testing
test = np.random.random(input_shape)[np.newaxis,...]
layer_outs = functor([test, 1.])

แต่ฉันได้รับข้อผิดพลาดนี้ TypeError: ไม่สามารถแปลง 1.0 เป็น EagerTensor ของ dtype int32


person anurag shrivastava    schedule 09.07.2020    source แหล่งที่มา
comment
เปลี่ยน 1. (ทศนิยม) เป็น 1 (จำนวนเต็ม)   -  person Dr. Snoopy    schedule 09.07.2020
comment
สวัสดี หากคุณลบ k.learning_phase() และเรียกใช้ฟังก์ชันโดยใช้อินพุตทดสอบเท่านั้น ตัวอย่างของคุณจะทำงานได้อย่างสมบูรณ์ ที่จริงแล้ว K.learning_phase ช่วยในการพิจารณาว่าเป็นการฝึกหรือการทดสอบ และคุณสามารถตั้งค่าแยกเป็น K.set_learning_phase ได้ หากคุณชอบแนวทางนี้ ฉันสามารถอัปโหลดตัวอย่างของฉันได้ โปรดจำไว้ว่า API สำหรับ K.function รับอินพุต เอาท์พุต อัปเดต kwargs ดังที่แสดงไว้ที่นี่ tensorflow.org/api_docs/python/tf/keras/backend/function สำหรับข้อมูลเพิ่มเติมเกี่ยวกับ K.function โปรดดู stackoverflow.com/questions/48142181/ ดีที่สุด   -  person smile    schedule 09.07.2020
comment
สวัสดี หากคุณยินดีที่จะปิดการใช้งาน tf.compat.v1.disable_eager_execution() โมเดลของคุณควรทำงานได้ดีเหมือนเดิม ดีที่สุด   -  person smile    schedule 09.07.2020