我用Tesla K40训练了TF / Keras模型(UNet架构)。当我使用它与Jetson AGX Xavier(Jetpack 4.4.1)进行推理时,如果批处理大小大于3,我将得到截然不同的结果。如果未设置,则model.predict()方法中的batch_size默认为32,并且如果仅传递3个或更少的输入,或者传递我的输入数据的整个集合,但在model.predict()方法中指定batch_size = 3(或更少),我只会得到正确的结果。
这是代码:
import os
import numpy as np
from tensorflow import keras as K
import cdUtils
import cdModels
from libtiff import TIFF
img_size = 128
classes = 1
channels = 13
model_dir = '../models/'
model_name = 'EF_bce'
model = K.models.load_model(model_dir + model_name)
model.summary()
dataset_dir = '../imgs_pisa/'
img_pre = 'pisa_pre/'
img_post = 'pisa_post/'
cm_name = 'pisa-cm_' + model_name
res_dir = '../res_pisa/'
os.makedirs(res_dir, exist_ok=True)
raster_pre = cdUtils.build_raster(dataset_dir + img_pre)
raster_post = cdUtils.build_raster(dataset_dir + img_post)
raster = np.concatenate((raster_pre,raster_post), axis=2)
padded_raster = cdUtils.pad(raster, img_size)
test_image = cdUtils.crop(padded_raster, img_size, img_size)
# Create inputs for the Neural Network
inputs = np.asarray(test_image, dtype='float32')
inputs_1 = inputs[:,:,:,:channels]
inputs_2 = inputs[:,:,:,channels:]
inputs = [inputs_1, inputs_2]
# Perform inference
results = model.predict(inputs)
print('Results: ', results)
print('Inference done!')
我检查了预处理功能(未包含在此代码段中)是否正常工作,并且输入在每个设备上始终匹配。即使我在运行时没有错误,这可能是内存问题吗?
谢谢。