我很确定这是一个错误-尽管正在寻找解决方法。我将注意到,我使用CNN作为特征提取器,然后使用tf.signal的滑动窗口使CNN的输出倍数,然后馈入密集网络。因此,这是一个有点奇怪的体系结构(有充分的理由)-但我希望渐变仅能在整个窗口框架内平均(真的,我不在乎-只需以某种合理的方式进行处理即可)。无论如何-一个示例模型.....假设args.num_frames = 6。
import sys
import pygame
class Skel():
def __init__(self, screen):
#Initialize skeleteon and set screen
self.screen = screen
#Get rectangle of skeleton and screen
self.image = pygame.image.load("EM17_skeleton.bmp")
self.rect = self.image.get_rect()
self.screen_rect = screen.get_rect()
#Place skeleton at center
self.rect.centerx = self.screen_rect.centerx
self.rect.centery = self.screen_rect.centery
def draw(self,screen):
"""Draw skeleton at location"""
screen.blit(self.image, self.rect)
skel = Skel(screen)
def run_game(self):
pygame.init()
screen = pygame.display.set_mode((400,400))
#Set background color
bg_color = (0,0,160)
#Set loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(bg_color)
skel.draw(screen)
pygame.display.flip()
run_game()
现在,如果我们这样做......
inputs = tf.keras.Input(shape=data_loader_train[0][0][0].shape, name='img') ## (108, 192, 3)
x = layers.Conv2D(32, 3, activation='relu')(inputs)
x = layers.Conv2D(16, 3, activation='relu')(x)
block_1_output = layers.MaxPooling2D(2)(x)
x = layers.Conv2D(16, 3, activation='relu', padding='same')(block_1_output)
block_2_output = layers.add([x, block_1_output])
block_2_output = layers.MaxPooling2D(2)(block_2_output)
x = layers.Conv2D(16, 3, activation='relu', padding='same')(block_2_output)
block_3_output = layers.add([x, block_2_output])
block_3_output = layers.MaxPooling2D(2)(block_3_output)
x = layers.Conv2D(32, 3, activation='relu')(block_3_output)
x = layers.GlobalAveragePooling2D()(x)
### if this part is included we get an error ##########
x = layers.Flatten()(x)
x = tf.signal.frame(x,args.num_frames,1, axis=0)
x = layers.Flatten()(x)
##############################
x = layers.Dense(16, activation='relu')(x)
x = layers.Dense(1)(x)
counts = tf.keras.activations.softplus(x)
model = tf.keras.Model(inputs, counts, name='toy_resnet')
在“ grads = ...”处出现以下错误
Error = AssertionError:期望所有args是张量或变量;但是得到了CompositeTensor:[