Run on Google Colab View source on GitHub Download notebook

Connect to EvaDB#

%pip install --quiet evadb
import evadb
cursor = evadb.connect().cursor()
[notice] A new release of pip is available: 23.0.1 -> 23.1.2
[notice] To update, run: pip install --upgrade pip
Note: you may need to restart the kernel to use updated packages.
Downloading to
  0%|          | 0.00/49.7M [00:00<?, ?B/s]
 10%|β–ˆ         | 5.16M/49.7M [00:00<00:00, 54.1MB/s]
 51%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ     | 25.4M/49.7M [00:00<00:00, 147MB/s] 
 92%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–| 45.5M/49.7M [00:00<00:00, 176MB/s]
100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 49.7M/49.7M [00:00<00:00, 163MB/s]

Download the video and load it into EvaDB#

# Getting MNIST as a video
!wget -nc

# Load the video into EvaDB
cursor.query("DROP TABLE IF EXISTS MNISTVid").df()
cursor.load("mnist.mp4", "MNISTVid", format="video").df()
File β€˜mnist.mp4’ already there; not retrieving.
0 Number of loaded VIDEO: 1

Run the Image Classification Function over the video#

# Connecting to the table with the loaded video
query = cursor.table("MNISTVid")

# Here, id refers to the frame id
# Each frame in the loaded MNIST video contains a digit
query = query.filter("id = 30 OR id = 50 OR id = 70 OR id = 0 OR id = 140")

# We are retrieving the frame "data" and 
# the output of the Image Classification function on the data 
# ("MnistImageClassifier(data).label")
query ="data, MnistImageClassifier(data).label")

response = query.df()
2023-06-08 01:26:32,405	INFO -- Started a local Ray instance.

Visualize output of query on the video#

# !pip install matplotlib
import matplotlib.pyplot as plt
import numpy as np

# create figure (fig), and array of axes (ax)
fig, ax = plt.subplots(nrows=1, ncols=5, figsize=[6,8])

for axi in ax.flat:
    idx = np.random.randint(len(response))
    img = response[''].iloc[idx]
    label = response['mnistimageclassifier.label'].iloc[idx]
    axi.set_title(f'label: {label}')