-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEVX:179]: Reuse Dataset Upload examples (#146)
* reuse dataset upload examples
- Loading branch information
Showing
43 changed files
with
571 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## Dataset upload from local directory | ||
|
||
Examples of how to upload your local directory datasets into clarifai app using `module_dir` feature from `Dataset`. | ||
|
||
**Note:** | ||
**Note:** | ||
|
||
- Ensure that the `CLARIFAI_PAT` environment variable is set. | ||
- Ensure that the appropriate base workflow is being set for indexing respective input type. | ||
|
||
|
||
## Image Classification - Cifar10 | ||
```python | ||
from clarifai.client.dataset import Dataset | ||
dataset = Dataset(user_id="user_id", app_id="app_id", dataset_id="dataset_id") | ||
dataset.upload_dataset(task="visual_classification", split="train", module_dir="path_to_cifar10_module") | ||
``` | ||
|
||
## Image Classification - [Food-101](https://data.vision.ee.ethz.ch/cvl/datasets_extra/food-101/) | ||
```python | ||
from clarifai.client.dataset import Dataset | ||
dataset = Dataset(user_id="user_id", app_id="app_id", dataset_id="dataset_id") | ||
dataset.upload_dataset(task="visual_classification", split="train", module_dir="path_to_food-101_module") | ||
``` | ||
|
||
## Text Classification - IMDB Reviews | ||
```python | ||
from clarifai.client.dataset import Dataset | ||
dataset = Dataset(user_id="user_id", app_id="app_id", dataset_id="dataset_id") | ||
dataset.upload_dataset(task="text_clf", split="train", module_dir="path_to_imdb_reviews_module") | ||
``` |
Empty file.
Empty file.
10 changes: 10 additions & 0 deletions
10
clarifai/datasets/upload/examples/image_classification/cifar10/cifar_small_test.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
image_path,label | ||
images/test_batch_700.jpg,horse | ||
images/test_batch_701.jpg,bird | ||
images/test_batch_702.jpg,deer | ||
images/test_batch_703.jpg,ship | ||
images/test_batch_704.jpg,horse | ||
images/test_batch_705.jpg,deer | ||
images/test_batch_706.jpg,bird | ||
images/test_batch_707.jpg,truck | ||
images/test_batch_709.jpg,ship |
10 changes: 10 additions & 0 deletions
10
clarifai/datasets/upload/examples/image_classification/cifar10/cifar_small_train.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
image_path,label | ||
images/test_batch_700.jpg,horse | ||
images/test_batch_701.jpg,bird | ||
images/test_batch_702.jpg,deer | ||
images/test_batch_703.jpg,ship | ||
images/test_batch_704.jpg,horse | ||
images/test_batch_705.jpg,deer | ||
images/test_batch_706.jpg,bird | ||
images/test_batch_707.jpg,truck | ||
images/test_batch_709.jpg,ship |
42 changes: 42 additions & 0 deletions
42
clarifai/datasets/upload/examples/image_classification/cifar10/dataset.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#! Cifar10 Dataset | ||
|
||
import csv | ||
import os | ||
|
||
from clarifai.datasets.upload.base import ClarifaiDataLoader | ||
from clarifai.datasets.upload.features import VisualClassificationFeatures | ||
|
||
|
||
class Cifar10DataLoader(ClarifaiDataLoader): | ||
"""Cifar10 Dataset.""" | ||
|
||
def __init__(self, split: str = "train"): | ||
"""Initialize dataset params. | ||
Args: | ||
split: "train" or "test" | ||
""" | ||
self.split = split | ||
self.data_dirs = { | ||
"train": os.path.join(os.path.dirname(__file__), "cifar_small_train.csv"), | ||
"test": os.path.join(os.path.dirname(__file__), "cifar_small_test.csv") | ||
} | ||
self.data = self.load_data() | ||
|
||
def load_data(self): | ||
data = [] | ||
with open(self.data_dirs[self.split]) as _file: | ||
reader = csv.reader(_file) | ||
next(reader, None) # skip header | ||
for review in reader: | ||
data.append((review[0], review[1])) | ||
return data | ||
|
||
def __getitem__(self, index): | ||
item = self.data[index] | ||
return VisualClassificationFeatures( | ||
image_path=os.path.join(os.path.dirname(__file__), item[0]), | ||
label=item[1], | ||
id=os.path.basename(item[0]).split(".")[0]) | ||
|
||
def __len__(self): | ||
return len(self.data) |
Binary file added
BIN
+963 Bytes
...datasets/upload/examples/image_classification/cifar10/images/test_batch_700.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+921 Bytes
...datasets/upload/examples/image_classification/cifar10/images/test_batch_701.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+907 Bytes
...datasets/upload/examples/image_classification/cifar10/images/test_batch_702.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+828 Bytes
...datasets/upload/examples/image_classification/cifar10/images/test_batch_703.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+922 Bytes
...datasets/upload/examples/image_classification/cifar10/images/test_batch_704.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+877 Bytes
...datasets/upload/examples/image_classification/cifar10/images/test_batch_705.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+859 Bytes
...datasets/upload/examples/image_classification/cifar10/images/test_batch_706.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+937 Bytes
...datasets/upload/examples/image_classification/cifar10/images/test_batch_707.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+875 Bytes
...datasets/upload/examples/image_classification/cifar10/images/test_batch_708.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+826 Bytes
...datasets/upload/examples/image_classification/cifar10/images/test_batch_709.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
39 changes: 39 additions & 0 deletions
39
clarifai/datasets/upload/examples/image_classification/food-101/dataset.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
|
||
from clarifai.datasets.upload.base import ClarifaiDataLoader | ||
from clarifai.datasets.upload.features import VisualClassificationFeatures | ||
|
||
|
||
class Food101DataLoader(ClarifaiDataLoader): | ||
"""Food-101 Image Classification Dataset.""" | ||
|
||
def __init__(self, split: str = "train"): | ||
"""Initialize dataset params. | ||
Args: | ||
split: "train" or "test" | ||
""" | ||
self.split = split | ||
self.image_dir = {"train": os.path.join(os.path.dirname(__file__), "images")} | ||
self.load_data() | ||
|
||
def load_data(self): | ||
"""Load data for the food-101 dataset.""" | ||
self.data = [] | ||
class_names = os.listdir(self.image_dir[self.split]) | ||
for class_name in class_names: | ||
for image in os.listdir(os.path.join(self.image_dir[self.split], class_name)): | ||
image_path = os.path.join(self.image_dir[self.split], class_name, image) | ||
self.data.append({ | ||
"image_path": image_path, | ||
"class_name": class_name, | ||
}) | ||
|
||
def __getitem__(self, idx): | ||
data_item = self.data[idx] | ||
image_path = data_item["image_path"] | ||
class_name = data_item["class_name"] | ||
return VisualClassificationFeatures( | ||
image_path=image_path, label=class_name, id=os.path.basename(image_path).split(".")[0]) | ||
|
||
def __len__(self): | ||
return len(self.data) |
Binary file added
BIN
+47.9 KB
...asets/upload/examples/image_classification/food-101/images/beignets/1420783.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+48.1 KB
...asets/upload/examples/image_classification/food-101/images/beignets/3287885.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.4 KB
...asets/upload/examples/image_classification/food-101/images/beignets/3617075.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+33 KB
...atasets/upload/examples/image_classification/food-101/images/beignets/38052.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+46.6 KB
...atasets/upload/examples/image_classification/food-101/images/beignets/39147.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.8 KB
...asets/upload/examples/image_classification/food-101/images/hamburger/139558.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45.9 KB
...sets/upload/examples/image_classification/food-101/images/hamburger/1636096.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45.1 KB
...sets/upload/examples/image_classification/food-101/images/hamburger/2480925.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+36.5 KB
...sets/upload/examples/image_classification/food-101/images/hamburger/3385808.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+31.8 KB
...sets/upload/examples/image_classification/food-101/images/hamburger/3647386.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+25.7 KB
...sets/upload/examples/image_classification/food-101/images/prime_rib/1826869.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.3 KB
...sets/upload/examples/image_classification/food-101/images/prime_rib/2243245.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.6 KB
...asets/upload/examples/image_classification/food-101/images/prime_rib/259212.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+46.5 KB
...sets/upload/examples/image_classification/food-101/images/prime_rib/2842688.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+51.4 KB
...sets/upload/examples/image_classification/food-101/images/prime_rib/3035414.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+43.8 KB
...datasets/upload/examples/image_classification/food-101/images/ramen/1545393.jpg
Oops, something went wrong.
Binary file added
BIN
+48.8 KB
...datasets/upload/examples/image_classification/food-101/images/ramen/2427642.jpg
Oops, something went wrong.
Binary file added
BIN
+50.1 KB
...datasets/upload/examples/image_classification/food-101/images/ramen/3520891.jpg
Oops, something went wrong.
Binary file added
BIN
+33.8 KB
.../datasets/upload/examples/image_classification/food-101/images/ramen/377566.jpg
Oops, something went wrong.
Binary file added
BIN
+55.5 KB
.../datasets/upload/examples/image_classification/food-101/images/ramen/503504.jpg
Oops, something went wrong.
Empty file.
Empty file.
37 changes: 37 additions & 0 deletions
37
clarifai/datasets/upload/examples/text_classification/imdb_dataset/dataset.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import csv | ||
import os | ||
|
||
from clarifai.datasets.upload.base import ClarifaiDataLoader | ||
from clarifai.datasets.upload.features import TextFeatures | ||
|
||
|
||
class IMDBMovieReviewsDataLoader(ClarifaiDataLoader): | ||
"""IMDB 50K Movie Reviews Dataset.""" | ||
|
||
def __init__(self, split: str = "train"): | ||
"""Initialize dataset params. | ||
Args: | ||
split: "train" or "test" | ||
""" | ||
self.split = split | ||
self.data_dirs = { | ||
"train": os.path.join(os.path.dirname(__file__), "train.csv"), | ||
"test": os.path.join(os.path.dirname(__file__), "test.csv") | ||
} | ||
self.data = [] | ||
|
||
self.load_data() | ||
|
||
def load_data(self): | ||
with open(self.data_dirs[self.split]) as _file: | ||
reader = csv.reader(_file) | ||
next(reader, None) # skip header | ||
for review in reader: | ||
self.data.append({"text": review[0], "labels": review[1], "id": None}) | ||
|
||
def __getitem__(self, idx): | ||
item = self.data[idx] | ||
return TextFeatures(text=item["text"], labels=item["labels"], id=item["id"]) | ||
|
||
def __len__(self): | ||
return len(self.data) |
Oops, something went wrong.