web-dev-qa-db-ja.com

AttributeError: 'google.protobuf.pyext._message.RepeatedCompositeCo'オブジェクトに属性 'append'がありません

私は、Google CollabのMobileNetv2事前トレーニング済みモデルで転移学習モデルを構築しています。昨日まで、すべてが順調でした。しかし、今日、実行時に

#Create the base model(feature_extractor) from the pre-trained model MobileNet V2
_URL = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/2"
feature_extractor = hub.KerasLayer(_URL, input_shape=(_TARGET_SIZE, _TARGET_SIZE,3))

エラーが発生します:


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-29-663d4cbb70df> in <module>()
      2 _TARGET_SIZE = 224
      3 _URL = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/2"
----> 4 feature_extractor = hub.KerasLayer(_URL, input_shape=(_TARGET_SIZE, _TARGET_SIZE,3))
      5 #print(feature_extractor._layers)


/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py in _variable_handle_from_shape_and_dtype(shape, dtype, shared_name, name, graph_mode, initial_value)
    165     handle_data = cpp_shape_inference_pb2.CppShapeInferenceResult.HandleData()
    166     handle_data.is_set = True
--> 167     handle_data.shape_and_type.append(
    168         cpp_shape_inference_pb2.CppShapeInferenceResult.HandleShapeAndType(
    169             shape=shape.as_proto(), dtype=dtype.as_datatype_enum))

AttributeError: 'google.protobuf.pyext._message.RepeatedCompositeCo' object has no attribute 'append'

なぜこれが発生するのか、そして/ usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/resource_variable_ops.pyファイルにアクセスして変更を加える必要があるのでしょうか?更新の問題に関連していると思います。それに取り組む方法について何か助けはありますか?

6
Pe Dro

Tensorflow(バージョン2.2.0-dev20200128)で同じエラーが発生し、protobufをアップグレードして修正しました(これについては issue で説明しています):

pip install -U protobuf==3.8.0

または、ノートブック(Google Colabノートブックなど)を使用している場合は、次のことを試してください。

!pip install -U protobuf==3.8.0
2
Masoud Maleki

ファイルから「新規Python 3ノートブック」を開いて、そこにコードを書き込んでみてください。問題が解決しました。

1
Progga Ilma

私はテンソルフローをインストールし、同じ問題が発生しました、私がしたこと:

ステップ1:protobufを次のようにアップグレードしました:

pip install -U protobuf==3.8.0

ステップ2:すべてを閉じるか、python環境を再起動します。

0
Usman Mushtaq