実現したいこと
書籍(Deep Learning with Python, Third Edition(MEAP))に記載の転移学習に関するコードをエラーなく実行したいです。
発生している問題・分からないこと
エラーが発生しました。
エラーメッセージ
error
1--------------------------------------------------------------------------- 2ImportError Traceback (most recent call last) 3File c:\Users\XXX\anaconda3\envs\keras3\Lib\site-packages\keras\src\ops\operation.py:234, in Operation.from_config(cls, config) 4 233 try: 5--> 234 return cls(**config) 6 235 except Exception as e: 7 8File c:\Users\XXX\anaconda3\envs\keras3\Lib\site-packages\keras_hub\src\layers\preprocessing\image_converter.py:216, in ImageConverter.__init__(self, image_size, scale, offset, crop_to_aspect_ratio, pad_to_aspect_ratio, interpolation, antialias, bounding_box_format, data_format, **kwargs) 9 214 offset = [-m / s for m, s in zip(kwargs.pop("mean"), std)] 10--> 216 super().__init__(**kwargs) 11 218 if crop_to_aspect_ratio and pad_to_aspect_ratio: 12 13File c:\Users\XXX\anaconda3\envs\keras3\Lib\site-packages\keras_hub\src\layers\preprocessing\preprocessing_layer.py:10, in PreprocessingLayer.__init__(self, **kwargs) 14 9 def __init__(self, **kwargs): 15---> 10 assert_tf_libs_installed(self.__class__.__name__) 16 11 super().__init__(**kwargs) 17 18File c:\Users\XXX\anaconda3\envs\keras3\Lib\site-packages\keras_hub\src\utils\tensor_utils.py:262, in assert_tf_libs_installed(symbol_name) 19 261 if tf_text is None or tf is None: 20--> 262 raise ImportError( 21 263 f"{symbol_name} requires `tensorflow` and `tensorflow-text` for " 22 264 "text processing. Run `pip install tensorflow-text` to install " 23 265 "both packages or visit https://www.tensorflow.org/install\n\n" 24 266 "If `tensorflow-text` is already installed, try importing it " 25 267 "in a clean python session. Your installation may have errors.\n\n" 26 268 "KerasHub uses `tf.data` and `tensorflow-text` to preprocess text " 27 269 "on all Keras backends. If you are running on Jax or Torch, this " 28 270 "installation does not need GPU support." 29 271 ) 30 31ImportError: ImageConverter requires `tensorflow` and `tensorflow-text` for text processing. Run `pip install tensorflow-text` to install both packages or visit https://www.tensorflow.org/install 32 33If `tensorflow-text` is already installed, try importing it in a clean python session. Your installation may have errors. 34 35KerasHub uses `tf.data` and `tensorflow-text` to preprocess text on all Keras backends. If you are running on Jax or Torch, this installation does not need GPU support. 36 37During handling of the above exception, another exception occurred: 38 39TypeError Traceback (most recent call last) 40File c:\Users\XXX\anaconda3\envs\keras3\Lib\site-packages\keras\src\saving\serialization_lib.py:718, in deserialize_keras_object(config, custom_objects, safe_mode, **kwargs) 41 717 try: 42--> 718 instance = cls.from_config(inner_config) 43 719 except TypeError as e: 44 45File c:\Users\XXX\anaconda3\envs\keras3\Lib\site-packages\keras\src\ops\operation.py:236, in Operation.from_config(cls, config) 46 235 except Exception as e: 47--> 236 raise TypeError( 48 237 f"Error when deserializing class '{cls.__name__}' using " 49 238 f"config={config}.\n\nException encountered: {e}" 50 239 ) 51 52TypeError: Error when deserializing class 'ImageConverter' using config={'name': 'image_converter', 'trainable': True, 'dtype': 'float32', 'image_size': (180, 180), 'scale': 0.00784313725490196, 'offset': -1.0, 'interpolation': 'bilinear', 'antialias': False, 'crop_to_aspect_ratio': True, 'pad_to_aspect_ratio': False, 'bounding_box_format': 'yxyx'}. 53 54Exception encountered: ImageConverter requires `tensorflow` and `tensorflow-text` for text processing. Run `pip install tensorflow-text` to install both packages or visit https://www.tensorflow.org/install 55 56If `tensorflow-text` is already installed, try importing it in a clean python session. Your installation may have errors. 57 58KerasHub uses `tf.data` and `tensorflow-text` to preprocess text on all Keras backends. If you are running on Jax or Torch, this installation does not need GPU support. 59 60During handling of the above exception, another exception occurred: 61 62TypeError Traceback (most recent call last) 63Cell In[27], line 1 64----> 1 preprocessor = keras_hub.layers.ImageConverter.from_preset('xception_41_imagenet', image_size=(180, 180)) 65 66File c:\Users\XXX\anaconda3\envs\keras3\Lib\site-packages\keras_hub\src\layers\preprocessing\image_converter.py:386, in ImageConverter.from_preset(cls, preset, **kwargs) 67 384 if cls.backbone_cls != backbone_cls: 68 385 cls = find_subclass(preset, cls, backbone_cls) 69--> 386 return loader.load_image_converter(cls, **kwargs) 70 71File c:\Users\XXX\anaconda3\envs\keras3\Lib\site-packages\keras_hub\src\utils\preset_utils.py:669, in KerasPresetLoader.load_image_converter(self, cls, **kwargs) 72 667 def load_image_converter(self, cls, **kwargs): 73 668 converter_config = load_json(self.preset, IMAGE_CONVERTER_CONFIG_FILE) 74--> 669 return self._load_serialized_object(converter_config, **kwargs) 75 76File c:\Users\XXX\anaconda3\envs\keras3\Lib\site-packages\keras_hub\src\utils\preset_utils.py:729, in KerasPresetLoader._load_serialized_object(self, config, **kwargs) 77 726 config = set_dtype_in_config(config, dtype) 78 728 config["config"] = {**config["config"], **kwargs} 79--> 729 return keras.saving.deserialize_keras_object(config) 80 81File c:\Users\XXX\anaconda3\envs\keras3\Lib\site-packages\keras\src\saving\serialization_lib.py:720, in deserialize_keras_object(config, custom_objects, safe_mode, **kwargs) 82 718 instance = cls.from_config(inner_config) 83 719 except TypeError as e: 84--> 720 raise TypeError( 85 721 f"{cls} could not be deserialized properly. Please" 86 722 " ensure that components that are Python object" 87 723 " instances (layers, models, etc.) returned by" 88 724 " `get_config()` are explicitly deserialized in the" 89 725 " model's `from_config()` method." 90 726 f"\n\nconfig={config}.\n\nException encountered: {e}" 91 727 ) 92 728 build_config = config.get("build_config", None) 93 729 if build_config and not instance.built: 94 95TypeError: <class 'keras_hub.src.layers.preprocessing.image_converter.ImageConverter'> could not be deserialized properly. Please ensure that components that are Python object instances (layers, models, etc.) returned by `get_config()` are explicitly deserialized in the model's `from_config()` method. 96 97config={'module': 'keras_hub.src.layers.preprocessing.image_converter', 'class_name': 'ImageConverter', 'config': {'name': 'image_converter', 'trainable': True, 'dtype': {'module': 'keras', 'class_name': 'DTypePolicy', 'config': {'name': 'float32'}, 'registered_name': None}, 'image_size': (180, 180), 'scale': 0.00784313725490196, 'offset': -1.0, 'interpolation': 'bilinear', 'antialias': False, 'crop_to_aspect_ratio': True, 'pad_to_aspect_ratio': False, 'bounding_box_format': 'yxyx'}, 'registered_name': 'keras_hub>ImageConverter'}. 98 99Exception encountered: Error when deserializing class 'ImageConverter' using config={'name': 'image_converter', 'trainable': True, 'dtype': 'float32', 'image_size': (180, 180), 'scale': 0.00784313725490196, 'offset': -1.0, 'interpolation': 'bilinear', 'antialias': False, 'crop_to_aspect_ratio': True, 'pad_to_aspect_ratio': False, 'bounding_box_format': 'yxyx'}. 100 101Exception encountered: ImageConverter requires `tensorflow` and `tensorflow-text` for text processing. Run `pip install tensorflow-text` to install both packages or visit https://www.tensorflow.org/install 102 103If `tensorflow-text` is already installed, try importing it in a clean python session. Your installation may have errors. 104 105KerasHub uses `tf.data` and `tensorflow-text` to preprocess text on all Keras backends. If you are running on Jax or Torch, this installation does not need GPU support.
該当のソースコード
Python
1preprocessor = keras_hub.layers.ImageConverter.from_preset('xception_41_imagenet', image_size=(180, 180))
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
pip install tensorflow-text
上記を実行すると下記エラーとなりインストールできませんでした。
ERROR: Could not find a version that satisfies the requirement tensorflow-text (from versions: none)
ERROR: No matching distribution found for tensorflow-text
ネット検索の結果、Version 2.10 や 2.5 が良いとあったので試してみたが同じエラーが出ました。(最新バージョンは2.19.0)
補足
Windows 11
Python 3.12.8
keras 3.7.0
keras-hub 0.21.1
tensorflow 2.18.0

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2025/07/15 00:01
2025/07/15 01:37
2025/07/15 02:41
2025/07/15 03:16