Keras TypeError: unsupported operand type(s) for : 'int' and 'Dimension'

记录一个简单的bug
在使用keras时,需要取出一个tensor的某一维作为下一层的维度(这里,我是在写attention)
代码:
dim = input.shape[1]
dense = Dense(dim,activation=‘softmax’)(input)
报错:
TypeError: unsupported operand type(s) for : ‘int’ and ‘Dimension’
解决:
只需要将dim转化成int型即可
dim = int(input.shape[1])
dense = Dense(dim,activation=‘softmax’)(input)

发布了22 篇原创文章 · 获赞 0 · 访问量 4444

猜你喜欢

转载自blog.csdn.net/Yolo_C/article/details/88414651