Skip to main content

IVA TPU Python API

Project description

IVA TPU Python API

Main entities

TPUDevice

TPUDevice is a device handle

TPUProgram

TPUProgram contains TPU instructions and weigths data

Example

import numpy as np
from iva_tpu import TPUDevice, TPUProgram

from iva_applications.resnet50 import image_to_tensor
from iva_applications.imagenet import tpu_tensor_to_classes
from PIL import Image

image = Image.open('ILSVRC2012_val_00000045.JPEG')
tensor = image_to_tensor(image)

device = TPUDevice()
program = TPUProgram("resnet50.tpu")
device.load(program)  # now device is ready to make inference

output = device.run([tensor], dtype=np.float32)
tpu_tensor_to_classes(output[0], top=1)

from timeit import timeit
timeit(lambda: device.run([tensor]), number=100)

TPU Raw buffer examples

from iva_tpu import TPUDevice, TPUProgram
program = TPUProgram("omega_program_dnn_quant_3.0.0.tpu")
device = TPUDevice()
device.load(program)

with open("f.bin", "rb") as f:
    buf=f.read()

device.set_input_buffer(buf, 0)
device.run_inference()

for i in range(3):
  o = device.get_output_buffer(i)
  with open(f"o{i}.bin", "wb") as f:
    f.write(o)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iva-tpu-10.6.7.tar.gz (127.9 kB view details)

Uploaded Source

File details

Details for the file iva-tpu-10.6.7.tar.gz.

File metadata

  • Download URL: iva-tpu-10.6.7.tar.gz
  • Upload date:
  • Size: 127.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.6.8

File hashes

Hashes for iva-tpu-10.6.7.tar.gz
Algorithm Hash digest
SHA256 d1ac754ec8d9addd26e52ae9c5ea5fa2cab7fc7b85a5c59282532cee56a41aca
MD5 a844f25423bdb7a7d53c8e9cdea7f96e
BLAKE2b-256 0907163232dc152cbb53ae48c532d107c9bcd3fd7d9c722560e9e28927378870

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page