中国建设银行网站官网下载安装,房地产网站制作公司,lng企业自建站,有什么做分销的几个网站前陣子有發問#xff0c;關於 python 動態 batch size 如何實現#xff0c;目前解決之前問題現在遇到的問題是當我把兩張圖片直接用 numpy concat 堆疊在一起 進行 acl.util.numpy_to_ptr 轉換成指針進行推理後#xff0c;得到的結果只有第一張圖片是對的#xff0c;第二張…前陣子有發問關於 python 動態 batch size 如何實現目前解決之前問題現在遇到的問題是當我把兩張圖片直接用 numpy concat 堆疊在一起 進行 acl.util.numpy_to_ptr 轉換成指針進行推理後得到的結果只有第一張圖片是對的第二張之後就是錯的想確認 batch size 大於1時一該要如何堆疊然後轉成 acl formatdef transfer_pic(input_path):input_path os.path.abspath(input_path)image_file Image.open(input_path)image_file image_file.resize((256, 256))img np.array(image_file)height img.shape[0]width img.shape[1]# 对图片进行切分取中间区域h_off (height - 224) // 2w_off (width - 224) // 2crop_img img[h_off:height - h_off, w_off:width - w_off, :]# rgb to bgr改变通道顺序img crop_img[:, :, ::-1]shape img.shapeimg img.astype(float16)img[:, :, 0] - 104img[:, :, 1] - 117img[:, :, 2] - 123img img.reshape([1] list(shape))img img.transpose([0, 3, 1, 2])result np.frombuffer(img.tobytes(), np.float16)return resultimg1 transfer_pic(path1)img2 transfer_pic(path2)datasets numpy.concatenate((img1, img2), axis0)temp_data_buffer input_datafor i, item in enumerate(temp_data_buffer):input_name acl.mdl.get_input_name_by_index(model_desc, i)if input_name ! dynamicFlag:ptr acl.util.numpy_to_ptr(datasets)print(ptr)ret acl.rt.memcpy(item[buffer],item[size],ptr,item[size],ACL_MEMCPY_HOST_TO_DEVICE)check_ret(acl.rt.memcpy, ret)else:print()假設圖片 224,224,3 經過 transfer_pic() 後得到 img.shape (150528, )把兩張圖片直接 numpy.concat 堆疊起來變成 datasets.shape (301056, )然後透過ptr acl.util.numpy_to_ptr(datasets)print(ptr)ret acl.rt.memcpy(item[buffer],item[size],ptr,item[size],ACL_MEMCPY_HOST_TO_DEVICE)這個思路是否有什麼問題才造成只有第一張圖片正確附上推論的代碼