Package: rikai
Join the community::heavy_exclamation_mark: This repository is still experimental. No API-compatibility is guaranteed.RikaiRikai is a framework specifically designed for AI workflows focused around large scale unstructured datasets
(e.g., images, videos, sensor data (future), text (future), and more).
Through every stage of the AI modeling workflow,
Rikai strives to offer a great developer experience when working with real-world AI datasets.The quality of an AI dataset can make or break an AI project, but tooling for AI data is sorely lacking in ergonomics.
As a result, practitioners must spend most of their time and effort wrestling with their data instead of innovating on the models and use cases.
Rikai alleviates the pain that AI practitioners experience on a daily basis dealing with the myriad of tedious data tasks,
so they can focus again on model-building and problem solving.To start trying Rikai right away, checkout theQuickstart Guide.Main FeaturesData formatThe core of Rikai is a data format ("rikai format") based onApache Parquet.
Rikai augments parquet with a rich collection of semantic types design specifically for unstructured data and annotations.IntegrationsRikai comes with an extensive set of I/O connectors. For ETL, Rikai is able to consume popular formats like ROS bags and Coco.
For analysis, it's easy to read Rikai data into pandas/spark DataFrames (Rikai handles serde for the semantic types).
And for training, Rikai allows direct creation of Pytorch/Tensorflow datasets without manual conversion.SQL-ML EngineRikai extends Spark SQL with ML capability which allows users to analyze Rikai datasets using own models with SQL
("Bring your own model")VisualizationCarefully crafted data-visualization embedded with semantic types, especially in Jupyter notebooks,
to help you visualize and inspect your AI data without having to remember complicated raw image manipulations.RoadmapImproved video supportText / sensors / geospatial supportVersioning support built into the datasetBetter Rikai UDT-supportDeclarative annotation API (think vega-lite for annotating images/videos)Integrations into dbt and BI toolsExamplefrompyspark.sqlimportRowfrompyspark.ml.linalgimportDenseMatrixfromrikai.typesimportImage,Box2dfromrikai.numpyimportwrapimportnumpyasnpdf=spark.createDataFrame([{"id":1,"mat":DenseMatrix(2,2,range(4)),"image":Image("s3://foo/bar/1.png"),"annotations":[Row(label="cat",mask=wrap(np.random.rand(256,256)),bbox=Box2d(xmin=1.0,ymin=2.0,xmax=3.0,ymax=4.0),)],}])df.write.format("rikai").save("s3://path/to/features")Train dataset inPytorchfromtorch.utils.dataimportDataLoaderfromtorchvisionimporttransformsasTfromrikai.pytorch.visionimportDatasettransform=T.Compose([T.Resize(640),T.ToTensor(),T.Normalize((0.485,0.456,0.406),(0.229,0.224,0.225))])dataset=Dataset("s3://path/to/features",image_column="image",transform=transform)loader=DataLoader(dataset,batch_size=32,num_workers=8,)forbatchinloader:predicts=model(batch.to("cuda"))Using a ML model in Spark SQL (experiemental)CREATEMODELyolo5OPTIONS(min_confidence=0.3,device="gpu",batch_size=32)USING"s3://bucket/to/yolo5_spec.yaml";SELECTid,ML_PREDICT(yolo5,image)FROMmy_datasetWHEREsplit="train"LIMIT100;Rikai can use MLflow as its model registry. This allows you to automatically pickup the latest
model version if you're using the mlflow model registry. Here is a list of supported model flavors:PyTorch (pytorch)Tensorflow (tensorflow)Scikit-learn (sklearn)CREATEMODELyolo5OPTIONS(min_confidence=0.3,device="gpu",batch_size=32)USING"mlflow:///yolo5_model/";SELECTid,ML_PREDICT(yolo5,image)FROMmy_datasetWHEREsplit="train"LIMIT100;For more details on the model spec, seeSQL-ML documentationGetting StartedCurrently Rikai is maintained forScala 2.12 and Python 3.7, 3.8, 3.9There are multiple ways to install Rikai:Try it using the includedDockerfile.Install via pippip install rikai, withextras for gcp, pytorch/tf, and others.Install fromsourceNote: if you want to use Rikai with your own pyspark, please consultrikai documentationfor tips.DockerThe included Dockerfile creates a standalone demo image with
Jupyter, Pytorch, Spark, and rikai preinstalled with notebooks for you
to play with the capabilities of the rikai feature store.To build and run the docker image from the current directory:# Clone the repogitclonegit@github.com:eto-ai/rikairikai# Build the docker imagedockerbuild--tagrikai--networkhost.# Run the imagedockerrun-p0.0.0.0:8888:8888/tcprikai:latestjupyterlab-ip0.0.0.0--port8888If successful, the console should then print out a clickable link to JupyterLab. You can also
open a browser tab and go tolocalhost:8888.Install from pypiBase rikai library can be installed with justpip install rikai. Dependencies for supporting
pytorch (pytorch and torchvision), jupyter (matplotlib and jupyterlab) are all part of
optional extras. Many open-source datasets also use Youtube videos so we've also added pafy and
youtube-dl as optional extras as well.For example, if you want to use pytorch in Jupyter to train models on rikai datasets in s3
containing Youtube videos you would run:pip install rikai[pytorch,jupyter,youtube]If you're not sure what you need and don't mind installing some extra dependencies, you can
simply install everything:pip install rikai[all]Install from sourceTo build from source you'll need python as well as Scala with sbt installed:# Clone the repogitclonegit@github.com:eto-ai/rikairikai# Build the jarsbtpublishLocal# Install python packagecdpython
pipinstall-e.# pip install -e .[all] to install all optional extras (see "Install from pypi")Utilitiespre-commitcan be helpful in keep consistent code format with the repository.
It can trigger reformat and extra things in your local machine before the CI force you to do it.If you want it, install and enablepre-commitpipinstallpre-commit
pre-commitinstall#in your local development directory#pre-commit installed at .git/hooks/pre-commitIf you want to uninstall it, it would be easy, too.pre-commit uninstall