1、Keras使用GPU报错
Failed to get convolution algorithm. This is probably because cuDNN failed to initialize
tensorflow.python.framework.errors_impl.InternalError: CUDA runtime implicit initialization on GPU:0 failed. Status: out of memory
2022-04-15 16:29:45.507697: F tensorflow/stream_executor/lib/statusor.cc:34] Attempting to fetch value instead of handling error Internal: failed initializing StreamExecutor for CUDA device ordinal 0: Internal: failed call to cuDevicePrimaryCtxRetain: CUDA_ERROR_OUT_OF_MEMORY: out of memory; total memory reported: 4294967296
2022-04-15 16:29:45.526654: E tensorflow/core/common_runtime/session.cc:91] Failed to create session: Internal: CUDA runtime implicit initialization on GPU:0 failed. Status: out of memory
2022-04-15 16:29:45.527010: E tensorflow/c/c_api.cc:2184] Internal: CUDA runtime implicit initialization on GPU:0 failed. Status: out of memory
Skipping registering GPU devices...
[low_level_alloc.cc : 555] RAW: Check new_pages != nullptr failed: VirtualAlloc failed
[low_level_alloc.cc : 555] RAW: Check new_pages != nullptr failed: VirtualAlloc failed
2022-04-15 16:41:45.948893: E tensorflow/core/common_runtime/session.cc:91] Failed to create session: Internal: CUDA runtime implicit initialization on GPU:0 failed. Status: out of memory
2022-04-15 16:41:45.949265: E tensorflow/c/c_api.cc:2184] Internal: CUDA runtime implicit initialization on GPU:0 failed. Status: out of memory
通过查阅资料
(1)解决
# 使用GPU,使用单GPU
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
# GPU内存不足问题
config = tf.compat.v1.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.8 # 分配80%的显存给程序使用
config.gpu_options.allow_growth = True # 按需分配显存
session = tf.compat.v1.Session(config=config)
# tf.compat.v1.keras.backend.set_session(session)
# keras.backend.clear_session() # 清理session
解决:
搜到的一些解决办法
https://blog.csdn.net/qq_38835585/article/details/108321628
https://blog.csdn.net/qq_38835585/article/details/108321628
https://zhuanlan.zhihu.com/p/171703337
https://blog.csdn.net/ayiya_Oese/article/details/114022167
https://blog.csdn.net/wangkun1340378/article/details/72782593/
2、
在导入预训练模型的时候报错
nput 0 of layer global_average_pooling2d_1 is incompatible with the layer: expected ndim=4, found ndim=2. Full shape received: (None, 1000)
解决:添加 include_top=False
# 构建不带分类器的预训练模型
mobile = MobileNet(weights='imagenet', include_top=False)
# mobile = MobileNetV2(weights='imagenet', include_top=False)
# include_top: 是否包括顶层的全连接层
3、
又是显存炸了
Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter state is not initialized. The process may be terminated.
https://blog.csdn.net/weixin_43987408/article/details/121364691
4、
plot_model报错
ImportError: ('Failed to import pydot. You must `pip install pydot` and install graphviz (https://graphviz.gitlab.io/download/), ', 'for `pydotprint` to work.')
https://blog.csdn.net/weixin_44852067/article/details/122069626
.