import sys
import numpy as np
from mindx.sdk import base
from mindx.sdk.base import ImageProcessor, Tensor
def create_image(input_path, device_id):
image_processor = ImageProcessor(device_id)
image = image_processor.decode(input_path, base.nv12)
print("Image height: ", image.height)
print("Image width: ", image.width)
def create_tensor():
tensor_np = np.ones((3, 3))
tensor = Tensor(tensor_np)
print("Tensor location:", tensor.device)
print("Tensor data type:", tensor.dtype)
print("Tensor shape:", tensor.shape)
def image_to_tensor(input_path, device_id):
image_processor = ImageProcessor(device_id)
image = image_processor.decode(input_path, base.nv12)
image_tensor = image.to_tensor()
print("Tensor location:", image_tensor.device)
image_tensor.to_host()
print("Tensor location after perform to_host():", image_tensor.device)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("This demo only accept only ONE parameter, execute the demo like 'python3 main.py image'")
sys.exit(1)
device_ = 0
input_ = "./input.jpg"
base.mx_init()
command = sys.argv[1]
if command == "image":
create_image(input_, device_)
elif command == "tensor":
create_tensor()
elif command == "i2t":
image_to_tensor(input_, device_)
else:
print("Only accept [image, tensor, i2t]")
base.mx_deinit()