Skip to content

Instantly share code, notes, and snippets.

@daniel-falk
Created September 20, 2023 14:24
Show Gist options
  • Save daniel-falk/689c018cb627d3a4c0cfe616ec85208b to your computer and use it in GitHub Desktop.
Save daniel-falk/689c018cb627d3a4c0cfe616ec85208b to your computer and use it in GitHub Desktop.
show_dataset.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/daniel-falk/689c018cb627d3a4c0cfe616ec85208b/show_dataset.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"!pip install deeplake[enterprise]"
],
"metadata": {
"id": "FTVVJmpgd_Fg"
},
"id": "FTVVJmpgd_Fg",
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!activeloop login -t <KEY>"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "3I0w5kMYeWql",
"outputId": "1a48bffd-67cd-4e1a-d624-6846a4a5ce11"
},
"id": "3I0w5kMYeWql",
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Successfully logged in to Activeloop.\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"import deeplake\n",
"\n",
"ds_in = deeplake.load(\n",
"'hub://fixedit/object_det_val'\n",
")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "_FpKr1xi5B1z",
"outputId": "aa18bc0f-9205-4f1c-fdf5-0a99737c5825"
},
"id": "_FpKr1xi5B1z",
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"/"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"This dataset can be visualized in Jupyter Notebook by ds.visualize() or at https://app.activeloop.ai/fixedit/object_det_val\n",
"\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"|"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"hub://fixedit/object_det_val loaded successfully.\n",
"\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"\r \r\r\r"
]
}
]
},
{
"cell_type": "code",
"source": [
"ds_in.tensors"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "vckWgVvP9RR4",
"outputId": "8b6b3bdf-4cbd-4f23-8be6-00154f2e3789"
},
"id": "vckWgVvP9RR4",
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{'boxes': Tensor(key='boxes'),\n",
" 'categories': Tensor(key='categories'),\n",
" 'images': Tensor(key='images')}"
]
},
"metadata": {},
"execution_count": 7
}
]
},
{
"cell_type": "code",
"source": [
"ds_out = deeplake.like('./outds', ds_in, overwrite=True)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "hueIqgEr5T-Q",
"outputId": "01018b16-23f9-446c-e05e-37221095f216"
},
"id": "hueIqgEr5T-Q",
"execution_count": 19,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"./outds loaded successfully.\n",
"\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"\r\r\r\r"
]
}
]
},
{
"cell_type": "code",
"source": [
"new_ids = [100, 2, 101, 233, 0, 10, 1]\n",
"small_view = ds_in[new_ids]"
],
"metadata": {
"id": "IMyYkvvZ7_a3"
},
"id": "IMyYkvvZ7_a3",
"execution_count": 20,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import numpy as np\n",
"\n",
"@deeplake.compute\n",
"def flip_vertical(sample_in, sample_out):\n",
" sample_out.append({\n",
" 'categories': sample_in.categories.numpy(),\n",
" 'boxes': sample_in.boxes.numpy(),\n",
" 'images': np.flip(sample_in.images.numpy(), axis = 0)\n",
" })\n",
"\n",
" return sample_out"
],
"metadata": {
"id": "66QuYthy82DQ"
},
"id": "66QuYthy82DQ",
"execution_count": 21,
"outputs": []
},
{
"cell_type": "code",
"source": [
"flip_vertical().eval(small_view, ds_out, num_workers = 2)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "UF9UNsV-9aik",
"outputId": "608075cc-16d3-4a02-a4e3-277f35a192fb"
},
"id": "UF9UNsV-9aik",
"execution_count": 22,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"Evaluating flip_vertical: 100%|██████████| 7/7 [00:19<00:00"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Synchronizing class labels...\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"\n",
"Evaluating class_label_sync: 100%|██████████| 7/7 [00:00<00:00\n",
"Evaluating flip_vertical: 100%|██████████| 7/7 [00:20<00:00\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"small_view.categories.numpy()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "7BbTB_X39iJk",
"outputId": "ab964a1c-5a8d-431c-8c6a-19466c25f654"
},
"id": "7BbTB_X39iJk",
"execution_count": 23,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([[1],\n",
" [1],\n",
" [1],\n",
" [0],\n",
" [1],\n",
" [1],\n",
" [1]], dtype=uint32)"
]
},
"metadata": {},
"execution_count": 23
}
]
},
{
"cell_type": "code",
"source": [
"ds_out.categories.numpy()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "DrYahkUD9uwL",
"outputId": "c14e38dc-1145-4b27-9c83-bb5858df88fc"
},
"id": "DrYahkUD9uwL",
"execution_count": 24,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([[1],\n",
" [1],\n",
" [1],\n",
" [0],\n",
" [1],\n",
" [1],\n",
" [1]], dtype=uint32)"
]
},
"metadata": {},
"execution_count": 24
}
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
},
"colab": {
"provenance": [],
"include_colab_link": true
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment