簡體   English   中英

無法在 Tensorflow 僅 CPU 版本中加載 model

[英]Unable to load model in Tensorflow CPU only version

環境:

  • Tensorflow :2.3.0(僅限 CPU)
  • Python:3.8.5
  • GPU :0
  • 操作系統:Ubuntu 20.04 LTS

問題陳述:

我很抱歉問了另一個新手問題,但我正在嘗試使用Tensorflow (CPU only version)中的load_model()方法加載 model 。

I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 1996330000 Hz

I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fc360269ab0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:

I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version

試圖:

我嘗試設置環境變量鏈接

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
import tensorflow as tf
from keras.models import load_model


model = tf.keras.models.load_model('path/to/location/model.model')

或者

import os
os.environ['CUDA_VISIBLE_DEVICES'] = ''
import tensorflow as tf
from keras.models import load_model


model = tf.keras.models.load_model('path/to/location/model.model')

注意:請檢查 model 是否在.model擴展名中


Q1。 無論如何要檢查我的.model擴展名中的 .model 嗎?


編輯:

根據@kosa回答model.summary()給我以下 output。

Model: "model"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
image (InputLayer)              [(None, 45, 168, 1)] 0                                            
__________________________________________________________________________________________________
conv2d (Conv2D)                 (None, 45, 168, 16)  160         image[0][0]                      
__________________________________________________________________________________________________
max_pooling2d (MaxPooling2D)    (None, 23, 84, 16)   0           conv2d[0][0]                     
__________________________________________________________________________________________________
conv2d_1 (Conv2D)               (None, 23, 84, 32)   4640        max_pooling2d[0][0]              
__________________________________________________________________________________________________
max_pooling2d_1 (MaxPooling2D)  (None, 12, 42, 32)   0           conv2d_1[0][0]                   
__________________________________________________________________________________________________
conv2d_2 (Conv2D)               (None, 12, 42, 32)   9248        max_pooling2d_1[0][0]            
__________________________________________________________________________________________________
max_pooling2d_2 (MaxPooling2D)  (None, 6, 21, 32)    0           conv2d_2[0][0]                   
__________________________________________________________________________________________________
batch_normalization_v1 (BatchNo (None, 6, 21, 32)    128         max_pooling2d_2[0][0]            
__________________________________________________________________________________________________
flatten (Flatten)               (None, 4032)         0           batch_normalization_v1[0][0]     
__________________________________________________________________________________________________
dense (Dense)                   (None, 64)           258112      flatten[0][0]                    
__________________________________________________________________________________________________
dense_1 (Dense)                 (None, 64)           258112      flatten[0][0]                    
__________________________________________________________________________________________________
dense_2 (Dense)                 (None, 64)           258112      flatten[0][0]                    
__________________________________________________________________________________________________
dense_3 (Dense)                 (None, 64)           258112      flatten[0][0]                    
__________________________________________________________________________________________________
dense_4 (Dense)                 (None, 64)           258112      flatten[0][0]                    
__________________________________________________________________________________________________
dense_5 (Dense)                 (None, 64)           258112      flatten[0][0]                    
__________________________________________________________________________________________________
dropout (Dropout)               (None, 64)           0           dense[0][0]                      
__________________________________________________________________________________________________
dropout_1 (Dropout)             (None, 64)           0           dense_1[0][0]                    
__________________________________________________________________________________________________
dropout_2 (Dropout)             (None, 64)           0           dense_2[0][0]                    
__________________________________________________________________________________________________
dropout_3 (Dropout)             (None, 64)           0           dense_3[0][0]                    
__________________________________________________________________________________________________
dropout_4 (Dropout)             (None, 64)           0           dense_4[0][0]                    
__________________________________________________________________________________________________
dropout_5 (Dropout)             (None, 64)           0           dense_5[0][0]                    
__________________________________________________________________________________________________
char_1 (Dense)                  (None, 36)           2340        dropout[0][0]                    
__________________________________________________________________________________________________
char_2 (Dense)                  (None, 36)           2340        dropout_1[0][0]                  
__________________________________________________________________________________________________
char_3 (Dense)                  (None, 36)           2340        dropout_2[0][0]                  
__________________________________________________________________________________________________
char_4 (Dense)                  (None, 36)           2340        dropout_3[0][0]                  
__________________________________________________________________________________________________
char_5 (Dense)                  (None, 36)           2340        dropout_4[0][0]                  
__________________________________________________________________________________________________
char_6 (Dense)                  (None, 36)           2340        dropout_5[0][0]                  
==================================================================================================
Total params: 1,576,888
Trainable params: 1,576,824
Non-trainable params: 64
__________________________________________________________________________________________________
None

可能沒有任何錯誤。 請嘗試model.summary()並檢查其 output。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM