Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Error, page 246, Knowledge Distillation #40

Open
dia2teen opened this issue Dec 24, 2023 · 0 comments
Open

Code Error, page 246, Knowledge Distillation #40

dia2teen opened this issue Dec 24, 2023 · 0 comments

Comments

@dia2teen
Copy link


KeyError Traceback (most recent call last)
in <cell line: 5>()
26 vars = s_model_2.trainable_variables
27 grad = tape.gradient(student_loss, vars)
---> 28 opt.apply_gradients(zip(grad, vars))
29
30 print("에포크 {}".format(e))

12 frames
/usr/local/lib/python3.10/dist-packages/keras/src/optimizers/optimizer.py in _update_step(self, gradient, variable)
231 return
232 if self._var_key(variable) not in self._index_dict:
--> 233 raise KeyError(
234 f"The optimizer cannot recognize variable {variable.name}. "
235 "This usually means you are trying to call the optimizer to "

KeyError: in user code:

File "/usr/local/lib/python3.10/dist-packages/keras/src/optimizers/optimizer.py", line 225, in _update_step_xla  *
    return self._update_step(gradient, variable)
File "/usr/local/lib/python3.10/dist-packages/keras/src/optimizers/optimizer.py", line 233, in _update_step  **
    raise KeyError(

KeyError: 'The optimizer cannot recognize variable dense_1/kernel:0. This usually means you are trying to call the optimizer to update different parts of the model separately. Please call `optimizer.build(variables)` with the full list of trainable variables before the training loop or use legacy optimizer `tf.keras.optimizers.legacy.Adam.'

page 246쪽에 있는 코드를 실행하면 Key Error가 발생합니다.
optimizer.build(variables)를 통해 변수의 리스트를 만드라는 건데, 어떻게 해결해야 할까요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant