Skip to content

Instantly share code, notes, and snippets.

View dmitriykovalev's full-sized avatar

Dmitriy Kovalev dmitriykovalev

View GitHub Profile

Python Image One-Liners

Convert image to raw RGB bytes:

python3 -c "import sys,PIL.Image;sys.stdout.buffer.write(PIL.Image.open(sys.stdin.buffer).resize((324, 324)).convert('RGB').tobytes())" <lena.png >lena_224x224.bin

Display raw RGB bytes:

python3 -c "import sys,PIL.Image;PIL.Image.frombytes('RGB',(324, 324),sys.stdin.buffer.read()).show()" 

Run Coral TFLite Model using IREE

Setup

  1. Build IREE using instructions
  2. Build iree-import-tflite tool:
cd integrations/tensorflow/
CC=clang CXX=clang++ bazel build --config=generic_clang iree_tf_compiler:iree-import-tflite
cd -

Clang Cross Compile

You may want to run the following comands in Docker environment:

sudo docker run -v `pwd`:/work -w /work -it --rm debian:bullseye

Install required packages:

dpkg --add-architecture arm64
@dmitriykovalev
dmitriykovalev / call-native-c-function-from-mlir.md
Last active December 17, 2024 00:55
Call native C function from MLIR

Call native C function from MLIR

The MLIR file is based on matmul-vs-matvec.mlir. C file is written from scratch and contains _mlir_ciface_matmul() function to multiply two matrices.

Project layout according to IREE bulild instructions:

.
├── iree [working directory]
└── iree-build
import json
import urllib.request
url = urllib.request.urlopen('https://api.github.com/repos/google-coral/pycoral/releases')
encoding = url.info().get_content_charset('utf-8')
releases = json.loads(url.read().decode(encoding))
artifacts = []
for release in releases:
for asset in release['assets']:
{
"font_size": 16,
"tab_size": 2,
"rulers": [80, 100, 120],
"draw_white_space": "all",
"spell_check": true,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"ensure_newline_at_eof_on_save": true,
"highlight_line": true,
int main() {
if (false) {
} else do
throw sizeof new signed long int const volatile();
while (false);
}
public static int parseInt(String s, int radix) {
if (s == null) {
throw new NullPointerException("s == null");
}
if (radix < 2) {
throw new IllegalArgumentException("base < 2");
}
final int len = s.length();
int main(int argc, char *argv[]) {
return 0;
}