実現したいこと
TensorFlow2.0を動かし、独自のモデルを作る
前提
https://www.youtube.com/watch?v=8ktcGQ-XreQ
上記を参考にしています。
発生している問題・エラーメッセージ
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8e in position 94: invalid start byte
該当のソースコード
以下のコードを実行するとエラーが出ます。
python model_main_tf2.py --pipeline_config_path==ssd_efficientdet_d0_512x512_coco17_tpu-8.config --model_dir==training --alsologtostderr
PS C:\Users\username\TF2\models\research\object_detection> python model_main_tf2.py --pipeline_config_path==ssd_e fficientdet_d0_512x512_coco17_tpu-8.config --model_dir==training --alsologtostderr 2023-02-22 13:11:03.705265: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimize d with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical op erations: AVX AVX2 To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2023-02-22 13:11:04.069853: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1616] Created device /job:localhost/ replica:0/task:0/device:GPU:0 with 2147 MB memory: -> device: 0, name: NVIDIA GeForce GTX 1650, pci bus id: 0000:0 1:00.0, compute capability: 7.5 INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0',) I0222 13:11:04.148620 3016 mirrored_strategy.py:374] Using MirroredStrategy with devices ('/job:localhost/replica: 0/task:0/device:GPU:0',) Traceback (most recent call last): File "C:\Users\username\TF2\models\research\object_detection\model_main_tf2.py", line 113, in <module> tf.compat.v1.app.run ( ) File "C:\Users\username\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\platform\app.py", line 36, in ru n _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "C:\Users\username\Anaconda3\envs\tf2\lib\site-packages\absl\app.py", line 308, in run _run_main(main, args) File "C:\Users\username\Anaconda3\envs\tf2\lib\site-packages\absl\app.py", line 254, in _run_main sys.exit(main(argv)) File "C:\Users\username\TF2\models\research\object_detection\model_main_tf2.py", line 104, in main model_lib_v2.train_loop( File "C:\Users\username\Anaconda3\envs\tf2\lib\site-packages\object_detection\model_lib_v2.py", line 505, in tr ain_loop configs = get_configs_from_pipeline_file( File "C:\Users\username\Anaconda3\envs\tf2\lib\site-packages\object_detection\utils\config_util.py", line 138, in get_configs_from_pipeline_file proto_str = f.read() File "C:\Users\username\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 114, in read self._preread_check() File "C:\Users\username\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 76, in _preread_check self._read_buf = _pywrap_file_io.BufferedInputStream( UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8e in position 94: invalid start byte
試したこと
①CSVファイルの文字コードとプログラムで読み取ろうとした文字コード(utf-8)が異なるため、読み込みエラーを起こしたとのことでしたので該当のコードを探してみました。
movielens.pyに下記があったので文字コードは大丈夫なのではないかと思いました。
def csv_to_joint_dataframe(data_dir, dataset): ratings = ratings_csv_to_dataframe(data_dir, dataset) with tf.io.gfile.GFile(os.path.join(data_dir, dataset, MOVIES_FILE)) as f: movies = pd.read_csv(f, encoding="utf-8")
②
ssd_efficientdet_d0_512x512_coco17_tpu-8.configのinput_pathとlabel_map_pathのパスを逆にするといいという記事を見つけたので試してみました。
before
1train_input_reader: { 2 label_map_path: "label_map.pbtxt" 3 tf_record_input_reader { 4 input_path: "train.record" 5 } 6} 7 8eval_config: { 9 metrics_set: "coco_detection_metrics" 10 use_moving_averages: false 11 batch_size: 1; 12} 13 14eval_input_reader: { 15 label_map_path: "label_map.pbtxt" 16 shuffle: false 17 num_epochs: 1 18 tf_record_input_reader { 19 input_path: "test.record" 20 } 21}
after
1train_input_reader: { 2 input_path: "train.record" 3 tf_record_input_reader { 4 label_map_path: "label_map.pbtxt" 5 } 6} 7 8eval_config: { 9 metrics_set: "coco_detection_metrics" 10 use_moving_averages: false 11 batch_size: 1; 12} 13 14eval_input_reader: { 15 input_path: "test.record" 16 shuffle: false 17 num_epochs: 1 18 tf_record_input_reader { 19 label_map_path: "label_map.pbtxt" 20 } 21}

0 コメント