当运行冻结模型时,Jetson Nano不断崩溃

问题描述

我的jetson nano一直挂着。一段时间后,它会向我发出内存不足警告,并且在计算机死机后不久。仅当在我的jetson nano上运行以下代码和模型时,才会发生这种情况,与我的h5模型相比,在我的计算机上它运行良好,甚至显示出帧速率降低。我用来运行冻结模型的代码如下所示:

import cv2
import numpy as np
import tensorflow as tf
from tensorflow.compat.v1 import ConfigProto
from tensorflow.io.gfile import GFile
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.mobilenet_v2 import preprocess_input
from tensorflow.compat.v1.keras import backend as K

model= 'ptls213_xception_trt.pb'
HEIGHT=224
WIDTH=224
tf_config = ConfigProto()
tf_config.gpu_options.allow_growth = True
tf_config.gpu_options.per_process_gpu_memory_fraction = 0.8
tf_sess = tf.compat.v1.Session(config=tf_config)
with GFile(model,"rb") as f:
    graph_def = tf.compat.v1.GraphDef()
    graph_def.ParseFromString(f.read())
    tf.import_graph_def(graph_def,name='')

input_names = ['input_1']
input_tensor_name = input_names[0] + ":0"
output_names = ['dense/softmax']
output_tensor_name = output_names[0] + ":0"
output_tensor = tf_sess.graph.get_tensor_by_name(output_tensor_name)

def Opfrozenpred(img):
    start_img = cv2.imread(img)
    start_img = cv2.resize(start_img,(HEIGHT,WIDTH))
    #x = image.img_to_array(start_img)
    x = np.expand_dims(start_img,axis=0)
    x = preprocess_input(x)
    Feed_dict = {input_tensor_name: x}
    preds = tf_sess.run(output_tensor,Feed_dict)
    return preds

preds= Opfrozenpred('Bus50/377.png')
print(preds)

请注意,尽管此代码将使我的nano崩溃,但使用下面的代码运行更大的h5模型也可以工作,即使确实需要一段时间:

import os
import cv2
from keras.models import load_model
from keras.applications.mobilenetnet_v2 import preprocess_input
import numpy as np

model = load_model('model.h5')

def predict(model,img):
    x= cv2.imread(img)
    x= cv2.resize(x,(224,224))
    x= np.expand_dims(x,axis=0)
    x= preprocess_inputs(x)
    preds= model.predict(x)
    preds[0]

e1= cv2.getTickCount()
preds= predict(model,'testimg.png')
e2= cv2.getTickCount()

time= (e2-e1)/cv2.getTickFrequency()
print(time)
print(preds)

对于造成此问题或我可以做什么的任何建议,我将不胜感激。谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)