인프런 커뮤니티 질문&답변

jihee.hwang님의 프로필 이미지
jihee.hwang

작성한 질문수

[개정판] 딥러닝 컴퓨터 비전 완벽 가이드

keras-retinanet 로드 모델 부분 오류

해결된 질문

작성

·

315

0

안녕하세요 강사님

keras-rentinanet 강의 부분 현재 따라하고 있는데요, 

로드 모델 부분에서 계속 같은 오류가 나서 문의드립니다.

오류 메세지는 아래와 같습니다.

항상 질문에 대해서 답변 주셔서 감사드립니다.

---------------------------------------------------------------------------
FailedPreconditionError                   Traceback (most recent call last)
c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\client\session.py in _do_call(self, fn, *args)
   1364     try:
-> 1365       return fn(*args)
   1366     except errors.OpError as e:

c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\client\session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
   1349       return self._call_tf_sessionrun(options, feed_dict, fetch_list,
-> 1350                                       target_list, run_metadata)
   1351 

c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\client\session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
   1442                                             fetch_list, target_list,
-> 1443                                             run_metadata)
   1444 

FailedPreconditionError: Error while reading resource variable pyramid_classification/Variable from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/pyramid_classification/Variable/class tensorflow::Var does not exist.
	 [[{{node pyramid_classification/ReadVariableOp}}]]

During handling of the above exception, another exception occurred:

FailedPreconditionError                   Traceback (most recent call last)
<ipython-input-30-de736d47f1ed> in <module>
      1 # 코랩 버전은 절대 경로로 수정.
      2 default_retina_dir= HOME_DIR
----> 3 training_model.load_weights(os.path.join(default_retina_dir, 'keras-retinanet/snapshots/resnet50_coco_best_v2.1.0.h5'),skip_mismatch=True,by_name=True)

c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras\engine\saving.py in load_wrapper(*args, **kwargs)
    490                 os.remove(tmp_filepath)
    491             return res
--> 492         return load_function(*args, **kwargs)
    493 
    494     return load_wrapper

c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras\engine\network.py in load_weights(self, filepath, by_name, skip_mismatch, reshape)
   1225                 saving.load_weights_from_hdf5_group_by_name(
   1226                     f, self.layers, skip_mismatch=skip_mismatch,
-> 1227                     reshape=reshape)
   1228             else:
   1229                 saving.load_weights_from_hdf5_group(

c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras\engine\saving.py in load_weights_from_hdf5_group_by_name(f, layers, skip_mismatch, reshape)
   1328                                                 weight_values[i]))
   1329 
-> 1330     K.batch_set_value(weight_value_tuples)

c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras\backend\tensorflow_backend.py in batch_set_value(tuples)
   2958             `value` should be a Numpy array.
   2959     """
-> 2960     tf_keras_backend.batch_set_value(tuples)
   2961 
   2962 

c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\keras\backend.py in batch_set_value(tuples)
   3257           assign_ops.append(assign_op)
   3258           feed_dict[assign_placeholder] = value
-> 3259         get_session().run(assign_ops, feed_dict=feed_dict)
   3260 
   3261 

c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\keras\backend.py in get_session(op_input_list)
    484   if not _MANUAL_VAR_INIT:
    485     with session.graph.as_default():
--> 486       _initialize_variables(session)
    487   return session
    488 

c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\keras\backend.py in _initialize_variables(session)
    908       v._keras_initialized = True
    909     if uninitialized_vars:
--> 910       session.run(variables_module.variables_initializer(uninitialized_vars))
    911 
    912 

c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
    954     try:
    955       result = self._run(None, fetches, feed_dict, options_ptr,
--> 956                          run_metadata_ptr)
    957       if run_metadata:
    958         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1178     if final_fetches or final_targets or (handle and feed_dict_tensor):
   1179       results = self._do_run(handle, final_targets, final_fetches,
-> 1180                              feed_dict_tensor, options, run_metadata)
   1181     else:
   1182       results = []

c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\client\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
   1357     if handle is None:
   1358       return self._do_call(_run_fn, feeds, fetches, targets, options,
-> 1359                            run_metadata)
   1360     else:
   1361       return self._do_call(_prun_fn, handle, feeds, fetches)

c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\client\session.py in _do_call(self, fn, *args)
   1382                     '\nsession_config.graph_options.rewrite_options.'
   1383                     'disable_meta_optimizer = True')
-> 1384       raise type(e)(node_def, op, message)
   1385 
   1386   def _extend_graph(self):

FailedPreconditionError: Error while reading resource variable pyramid_classification/Variable from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/pyramid_classification/Variable/class tensorflow::Var does not exist.
	 [[node pyramid_classification/ReadVariableOp (defined at c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\framework\ops.py:1748) ]]

Original stack trace for 'pyramid_classification/ReadVariableOp':
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\traitlets\config\application.py", line 664, in launch_instance
    app.start()
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\ipykernel\kernelapp.py", line 612, in start
    self.io_loop.start()
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tornado\platform\asyncio.py", line 149, in start
    self.asyncio_loop.run_forever()
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\asyncio\base_events.py", line 442, in run_forever
    self._run_once()
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\asyncio\base_events.py", line 1462, in _run_once
    handle._run()
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\asyncio\events.py", line 145, in _run
    self._callback(*self._args)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tornado\ioloop.py", line 690, in <lambda>
    lambda f: self._run_callback(functools.partial(callback, future))
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tornado\ioloop.py", line 743, in _run_callback
    ret = callback()
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tornado\gen.py", line 787, in inner
    self.run()
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tornado\gen.py", line 748, in run
    yielded = self.gen.send(value)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\ipykernel\kernelbase.py", line 365, in process_one
    yield gen.maybe_future(dispatch(*args))
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tornado\gen.py", line 209, in wrapper
    yielded = next(result)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\ipykernel\kernelbase.py", line 268, in dispatch_shell
    yield gen.maybe_future(handler(stream, idents, msg))
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tornado\gen.py", line 209, in wrapper
    yielded = next(result)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\ipykernel\kernelbase.py", line 545, in execute_request
    user_expressions, allow_stdin,
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tornado\gen.py", line 209, in wrapper
    yielded = next(result)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\ipykernel\ipkernel.py", line 306, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\ipykernel\zmqshell.py", line 536, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\IPython\core\interactiveshell.py", line 2867, in run_cell
    raw_cell, store_history, silent, shell_futures)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\IPython\core\interactiveshell.py", line 2895, in _run_cell
    return runner(coro)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\IPython\core\async_helpers.py", line 68, in _pseudo_sync_runner
    coro.send(None)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\IPython\core\interactiveshell.py", line 3072, in run_cell_async
    interactivity=interactivity, compiler=compiler, result=result)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\IPython\core\interactiveshell.py", line 3263, in run_ast_nodes
    if (await self.run_code(code, result,  async_=asy)):
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\IPython\core\interactiveshell.py", line 3343, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-28-2fca9b1f44b8>", line 8, in <module>
    config=args.config
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras_retinanet-0.5.1-py3.6-win-amd64.egg\keras_retinanet\bin\train.py", line 117, in create_models
    model          = model_with_weights(backbone_retinanet(num_classes, num_anchors=num_anchors, modifier=modifier, pyramid_levels=pyramid_levels), weights=weights, skip_mismatch=True)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras_retinanet-0.5.1-py3.6-win-amd64.egg\keras_retinanet\models\resnet.py", line 38, in retinanet
    return resnet_retinanet(*args, backbone=self.backbone, **kwargs)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras_retinanet-0.5.1-py3.6-win-amd64.egg\keras_retinanet\models\resnet.py", line 120, in resnet_retinanet
    return retinanet.retinanet(inputs=inputs, num_classes=num_classes, backbone_layers=backbone_layers, **kwargs)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras_retinanet-0.5.1-py3.6-win-amd64.egg\keras_retinanet\models\retinanet.py", line 295, in retinanet
    submodels = default_submodels(num_classes, num_anchors)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras_retinanet-0.5.1-py3.6-win-amd64.egg\keras_retinanet\models\retinanet.py", line 198, in default_submodels
    ('classification', default_classification_model(num_classes, num_anchors))
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras_retinanet-0.5.1-py3.6-win-amd64.egg\keras_retinanet\models\retinanet.py", line 71, in default_classification_model
    )(outputs)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras\engine\base_layer.py", line 463, in __call__
    self.build(unpack_singleton(input_shapes))
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras\layers\convolutional.py", line 147, in build
    constraint=self.bias_constraint)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras\engine\base_layer.py", line 279, in add_weight
    weight = K.variable(initializer(shape, dtype=dtype),
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\keras_retinanet-0.5.1-py3.6-win-amd64.egg\keras_retinanet\initializers.py", line 37, in __call__
    result = K.ones(shape, dtype=dtype) * -math.log((1 - self.probability) / self.probability)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\ops\variables.py", line 1079, in _run_op
    return tensor_oper(a.value(), *args, **kwargs)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py", line 524, in value
    return self._read_variable_op()
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py", line 608, in _read_variable_op
    self._dtype)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\ops\gen_resource_variable_ops.py", line 587, in read_variable_op
    "ReadVariableOp", resource=resource, dtype=dtype, name=name)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\framework\op_def_library.py", line 794, in _apply_op_helper
    op_def=op_def)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\util\deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\framework\ops.py", line 3357, in create_op
    attrs, op_def, compute_device)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\framework\ops.py", line 3426, in _create_op_internal
    op_def=op_def)
  File "c:\users\clxkh\anaconda3\envs\tf115\lib\site-packages\tensorflow_core\python\framework\ops.py", line 1748, in __init__
    self._traceback = tf_stack.extract_stack()

답변 4

1

권 철민님의 프로필 이미지
권 철민
지식공유자

현재까지 파악된 문제 원인은 얼마전에 keras-retinanet 패키지가 업데이트 되었는데  keras 2.3, tensorflow 1.15에서 train.py 수행시 문제가 발생하는 것 같습니다. keras-retinanet 패키지를 본격적으로 tensorflow 2.3, keras 2.4 버전으로 마이그레이션 해버린것 같습니다.

현재 제가 keras 2.4 버전에서 테스트 중입니다. 하지만 신규 keras-retinanet 패키지가 아직 안정화가 되지 않은 것 같습니다. 그리고 이를 적용하면 기존 강의 내용이 상당수 바뀌어야 할 것 같습니다.내용 정리 중이며 완료되면 언제까지 내용을 수정할지 전체 공지 하도록 하겠습니다. 

감사합니다.

0

권 철민님의 프로필 이미지
권 철민
지식공유자

해당 오류를 수정하였고, 전체 공지로 수정 방안을 말씀드렸으니 참조 부탁드립니다.
강의 새소식의 fizyr Keras Retinanet 패키지 버전 upgrade에 따른 강의 영상 변경 안내를 참조 부탁드립니다.

감사합니다.

0

jihee.hwang님의 프로필 이미지
jihee.hwang
질문자

넵 업데이트 기다리고 있겠습니다.

감사합니다~^^

0

권 철민님의 프로필 이미지
권 철민
지식공유자

안녕하십니까,

현재 keras-retinanet 패키지에서 내부적으로 변경이 일어났는데, 정확히 문제가 무엇인지 아직 모르겠습니다.  현재 계속 분석중이며, 일단은 retinanet 학습은 잠시 건너뛰시고 다음 학습으로 넘어가 주셨으면 합니다.  곧 다시 업데이트 드리겠습니다.

감사합니다.

jihee.hwang님의 프로필 이미지
jihee.hwang

작성한 질문수

질문하기