[케라스 창시자에게 배우는 딥러닝] 390pg 코드 8-27에서 질문이 있습니다.

308 views
Skip to first unread message

이보라

unread,
Aug 24, 2022, 1:23:50 AM8/24/22
to 머신러닝/딥러닝 도서 Q&A
안녕하세요 선생님! 공부 열심히하고 있습니다. 

다름이 아니라 책 390페이지 8-27코드 VAE 훈련하기 부분에서

마지막 부분인

vae.fit(x=x_train, y=None, shuffle=True, epochs=10, batch_size=batch_size, validation_data=(x_test, None))

fit하는 부분에 에러코드가 뜹니다. 코랩에서 실행하였고요. 
에러 내용은 아래와 같은데 혹시 제가 어떤 부분에서 실수하였는지 알 수 있을까요?ㅠㅠ

Epoch 1/10
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-20-af8de808fcf2> in <module> 17 epochs=10, 18 batch_size=batch_size, ---> 19 validation_data=(x_test, None))
1 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py in autograph_handler(*args, **kwargs) 1145 except Exception as e: # pylint:disable=broad-except 1146 if hasattr(e, "ag_error_metadata"): -> 1147 raise e.ag_error_metadata.to_exception(e) 1148 else: 1149 raise TypeError: in user code: File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1021, in train_function * return step_function(self, iterator) File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1010, in step_function ** outputs = model.distribute_strategy.run(run_step, args=(data,)) File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1000, in run_step ** outputs = model.train_step(data) File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 860, in train_step loss = self.compute_loss(x, y, y_pred, sample_weight) File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 919, in compute_loss y, y_pred, sample_weight, regularization_losses=self.losses) File "/usr/local/lib/python3.7/dist-packages/keras/engine/compile_utils.py", line 240, in __call__ total_loss_metric_value, sample_weight=batch_dim) File "/usr/local/lib/python3.7/dist-packages/keras/utils/metrics_utils.py", line 70, in decorated update_op = update_state_fn(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/keras/metrics.py", line 178, in update_state_fn return ag_update_state(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/keras/metrics.py", line 471, in update_state ** update_total_op = self.total.assign_add(value_sum) File "/usr/local/lib/python3.7/dist-packages/keras/engine/keras_tensor.py", line 255, in __array__ f'You are passing {self}, an intermediate Keras symbolic input/output, ' TypeError: You are passing KerasTensor(type_spec=TensorSpec(shape=(), dtype=tf.float32, name=None), name='tf.math.reduce_sum_4/Sum:0', description="created by layer 'tf.math.reduce_sum_4'"), an intermediate Keras symbolic input/output, to a TF API that does not allow registering custom dispatchers, such as `tf.cond`, `tf.function`, gradient tapes, or `tf.map_fn`. Keras Functional model construction only supports TF API calls that *do* support dispatching, such as `tf.math.add` or `tf.reshape`. Other APIs cannot be called directly on symbolic Kerasinputs/outputs. You can work around this limitation by putting the operation in a custom Keras layer `call` and calling that layer on this symbolic input/output.

Haesun Park

unread,
Aug 25, 2022, 5:35:44 AM8/25/22
to 이보라, 머신러닝/딥러닝 도서 Q&A
안녕하세요. 박해선입니다.

에러 메시지만으로는 어떤 문제인지 제가 알기 어렵습니다.
다만 코랩을 사용하신다면 깃허브에 있는 tf2 브랜치 코드를 참고하셔야 합니다.
책의 코드와 master 브랜치의 코드는 tf1.x 버전에 대응됩니다. 

변이형 오토인코더 예제 같은 경우 tf2 브랜치에는
tf.compat.v1.disable_v2_behavior()을 호출해 주는 문장이 추가되었고
몇몇 import 문이 책과 달라졌습니다.

감사합니다!

2022년 8월 24일 (수) 오후 2:23, 이보라 <harmo...@gmail.com>님이 작성:
--
이 메일은 Google 그룹스 '머신러닝/딥러닝 도서 Q&A' 그룹에 가입한 분들에게 전송되는 메시지입니다.
이 그룹에서 탈퇴하고 더 이상 이메일을 받지 않으려면 ml-dl-book-qn...@googlegroups.com에 이메일을 보내세요.
웹에서 이 토론을 보려면 https://groups.google.com/d/msgid/ml-dl-book-qna/2e036d1b-4b34-41c3-b9c0-1b24ee82d71en%40googlegroups.com을(를) 방문하세요.
Reply all
Reply to author
Forward
0 new messages