简体   繁体   中英

Unable to load model in Tensorflow CPU only version

Environment:

  • Tensorflow : 2.3.0 (CPU only)
  • Python: 3.8.5
  • GPU : 0
  • OS: Ubuntu 20.04 LTS

Problem Statement:

I'd like to apologise for asking another newbie question, but i'm trying to load model using load_model() method in Tensorflow (CPU only version) .

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

Attempt:

I tried setting environment variable link

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')

Or

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')

Note: Please check that model is in .model extension


Q1. Is there anyway to inspect my model which is in .model extension?


Edit:

As per @kosa answer model.summary() giving me following 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

There might not be any error. Please try model.summary() and check its output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM