나를 만들고 싶은 사용자 지정 keras 레이어(코드북에 대한 VQVAE 모델입니다.) 는 동안 훈련하고 싶가 tf.Variable
는 트랙의 사용은 각 코드 그래서 내가 다시 시작할 수 있습니다 사용하지 않는 코드입니다. 그래서 내가 만들어 내 코드북층 다음과 같이...
class Codebook(layers.Layer):
def __init__(self, num_codes, code_reset_limit = None, **kwargs):
super().__init__(**kwargs)
self.num_codes = num_codes
self.code_reset_limit = code_reset_limit
if self.code_reset_limit:
self.code_counter = tf.Variable(tf.zeros(num_codes, dtype = tf.int32), trainable = False)
def build(self, input_shape):
self.codes = self.add_weight(name = 'codes',
shape = (self.num_codes, input_shape[-1]),
initializer = 'random_uniform',
trainable = True)
super().build(input_shape)
문제를 좋아하는 Layer
클래스를 찾는 회원 변수 self.code_counter
고 목록에 추가합의 무게 저장되는 레이어. 그것은 또한 기대하고 self.code_counter
존재할 경우 무게가 로드되지 않는 경우 내에서 실행추는 모드입니다. 어떻게 만들 수 있습니다 그래서 keras 추적하지 않은 변수의 내 계층입니다. 나는 그것을 원하지 않는 지속적이거나 부분의 layers.weights
.