Open blue4683 opened 11 months ago
Tutorial Code for classifying image with inception_v3 using NNFW Python API from #11589 (comment)
inception_v3
$ pip install -i https://test.pypi.org/simple/ nnfwapi==0.1.1 $ pip install numpy $ pip install opencv-python
$ python3 minimal.py nnpackage_path backends(optional) operations(optional) label_path image_path
nnpackage_path
backends
operations
label_path
image_path
$ python3 minimal.py inception_v3 cpu label.txt goldfish.jfif
# minimal.py from nnfwapi.libnnfw_api_pybind import * import numpy as np import sys, cv2 def main(argv): args = len(argv) backends = "cpu" operations = "" if args < 3 or args > 6: print("Syntax Error") return if args == 3: nnpackage_path, label_path, image_path = argv elif args == 4: nnpackage_path, backends, label_path, image_path = argv else: nnpackage_path, backends, operations, label_path, image_path = argv labels = open(label_path).read().splitlines() session = nnfw_session(nnpackage_path, backends, operations) inputs = [] image = cv2.imread(image_path) image = cv2.resize(image, (299, 299)) input_image = np.array(image) / 255 inputs.append(input_image) input_size = session.input_size() session.set_inputs(input_size, inputs) outputs = session.inference() print("[Python]\tResult : " + labels[np.argmax(outputs[0])]) print() print("[Python]\tRun success") print() return if __name__ == "__main__": argv = sys.argv[1:] main(argv)
@glistening
Should I upload label.txt and image sample?
label.txt
No, but it would be helpful if you specify how you can label.txt.
Tutorial Code for classifying image with
inception_v3
using NNFW Python API from #11589 (comment)Install
Command
Arguments
nnpackage_path
: path of nnpackagebackends
: backends for use, default value is "cpu" (optional)operations
: assign a specific backends to each operation (optional)label_path
: path of label file that classification classes of modelimage_path
: path of image for classifyingExample
Code