LoginSignup
0
1

More than 3 years have passed since last update.

ViT(Vision Transformer)を動かしてみた、4つほど、うっ、Cifar10で80%超えた、ぼちぼちくるかー。【番外編】

Last updated at Posted at 2020-11-15

概要

以下のgithubに、いま注目されているViT(Vision Transformer)の実装が示されていたので、動かしてみた。
ただし、こちらは、エラーで動かすことができなかったもの。
Windows環境で作業しています。GPUあり。

(ERR01)
https://github.com/soumik12345/Vision-Transformer

本編は、
ViT(Vision Transformer)を動かしてみた、4つほど、うっ、Cifar10で80%超えた、ぼちぼちくるかー。すべて、他力です。cifar10、imagenet_resized/32x32、ちょっと、結果はまだ「?」付き。
です。
記載のとおり、Cifar10で80%超え、ありです。

動かなかった状態

いくつかのエラーは、解除でき、あとは、↓のエラーだけになったが、
TensorflowやPythonの知識不足で、解決できる気せず。。。
将来、瞬殺できるはずなので、備忘のため、エラーを残す。

下記のメッセージが意味があるのか、
何かの不具合で、意味のない領域に入って以下のエラーが出ているのかすら、区別がついていない。

RuntimeError: Method requires being in cross-replica context, use get_replica_context().merge_call()

全体を表示すると以下。(エラー対策で試行錯誤した後の内容になっているかもしれないが、基本的に、
以下の内容のエラーが出た。)

このエラーさえ、突破できれば、あとは実行できる感触を得ている。

Epoch 1/10
Traceback (most recent call last):
  File "main.py", line 18, in <module>
    history = model.fit(train_dataset, batch_size=64, epochs=10)
  File "C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\training.py", line 108, in _method_wrapper
    return method(self, *args, **kwargs)
  File "C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\training.py", line 1098, in fit
    tmp_logs = train_function(iterator)
  File "C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\def_function.py", line 780, in __call__
    result = self._call(*args, **kwds)
  File "C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\def_function.py", line 823, in _call
    self._initialize(args, kwds, add_initializers_to=initializers)
  File "C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\def_function.py", line 697, in _initialize
    *args, **kwds))
  File "C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\function.py", line 2855, in _get_concrete_function_internal_garbage_collected
    graph_function, _, _ = self._maybe_define_function(args, kwargs)
  File "C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\function.py", line 3213, in _maybe_define_function
    graph_function = self._create_graph_function(args, kwargs)
  File "C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\function.py", line 3075, in _create_graph_function
    capture_by_value=self._capture_by_value),
  File "C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\framework\func_graph.py", line 986, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\def_function.py", line 600, in wrapped_fn
    return weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\framework\func_graph.py", line 973, in wrapper
    raise e.ag_error_metadata.to_exception(e)
RuntimeError: in user code:

    C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\training.py:806 train_function  *
        return step_function(self, iterator)
    D:\_qiita\_vit8\Vision-Transformer-master\vision_transformer\transformer.py:84 train_step  *
        total_loss = self.distribute_strategy.reduce(
    C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\distribute\one_device_strategy.py:184 run  **
        return super(OneDeviceStrategy, self).run(fn, args, kwargs, options)
    C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\distribute\distribute_lib.py:1206 run
        with self.scope():
    C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\distribute\distribute_lib.py:386 __enter__
        self._context.strategy.extended)
    C:\Users\XYZZZ\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\distribute\distribute_lib.py:309 _require_cross_replica_or_default_context_extended
        raise RuntimeError("Method requires being in cross-replica context, use "

    RuntimeError: Method requires being in cross-replica context, use get_replica_context().merge_call()


D:\_qiita\_vit8\Vision-Transformer-master>


まとめ

特にありません。
コメントなどあれば、お願いします。

関連

ViT(Vision Transformer)を動かしてみた、4つほど、うっ、Cifar10で80%超えた、ぼちぼちくるかー。すべて、他力です。cifar10、imagenet_resized/32x32、ちょっと、結果はまだ「?」付き。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1