ITADN

[QUESTION] How can I convert nvcv.ImageBatchVarShape to torch tensor

#265Closedluongthecong123 创建于 2025-09-09
question
L
luongthecong123commented
[//]: # "SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved." [//]: # "SPDX-License-Identifier: Apache-2.0" [//]: # "" [//]: # "Licensed under the Apache License, Version 2.0 (the 'License');" [//]: # "you may not use this file except in compliance with the License." [//]: # "You may obtain a copy of the License at" [//]: # "http://www.apache.org/licenses/LICENSE-2.0" [//]: # "" [//]: # "Unless required by applicable law or agreed to in writing, software" [//]: # "distributed under the License is distributed on an 'AS IS' BASIS" [//]: # "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." [//]: # "See the License for the specific language governing permissions and" [//]: # "limitations under the License." **What is your question?** Hi, thank you for the great work. In the code below, I would like to convert a nvcv.ImageBatchVarShape into torch tensor for further operation but I don't know how. ``` from nvidia import nvimgcodec import cvcuda import torch decoder = nvimgcodec.Decoder() image_paths = ["images/img1.png", "images/img2.png"] # RGBA image with shape 384x384x4 batch_size = len(image_paths) image_list = decoder.read(image_paths) nvcvImages = cvcuda.as_images(image_list) # type: nvcv.ImageBatchVarShape nvcvImagesGray = cvcuda.cvtcolor(nvcvImages_adu, cvcuda.ColorConversion.RGB2GRAY) # type: nvcv.ImageBatchVarShape # Converting to pytorch tensor: ```
关闭于 2025-09-12 2 条评论