Man1103/PetImages
This is clone of popular Cats Vs. Dogs image classification dataset for CNN-based visual classification models. If you are using raw images (stored in /data), this script can be used for creating train-test split on the raw images dataset: def fetching_selected_data(cats_images_subpath: str, dogs_images_subpath: str, test_split: int, max_len: int = 1000000000): total_len = min(len(os.listdir(cats_images_subpath))… See the full description on the dataset page: https://huggingface.co/datasets/Man1103/PetImages.
143
This is clone of popular Cats Vs. Dogs image classification dataset for CNN-based visual classification models.
If you are using raw images (stored in /data), this script can be used for creating train-test split on the raw images dataset:
def fetching_selected_data(cats_images_subpath: str, dogs_images_subpath: str, test_split: int,
max_len: int = 1000000000):
total_len = min(len(os.listdir(cats_images_subpath)), len(os.listdir(dogs_images_subpath)), max_len)
training_set_count = int(total_len * (1 - (test_split/100)))
testing_set_count = total_len - training_set_count
def _get_image_files(parent_dir: str, first_count: int, max_count: int):
all_files = []
count = 0
for child in os.listdir(parent_dir):
grandchild = os.path.join(parent_dir, child)
if not os.path.isdir(grandchild):
count += 1
if os.path.isdir(grandchild):
continue
final_full_path = os.path.join(parent_dir, grandchild)
all_files.append(final_full_path)
else:
_get_image_files(grandchild)
last_count = first_count + max_count
return all_files[first_count:last_count]
def _get_input_labels(first_count: int, max_count: int):
cats_list = _get_image_files(cats_images_subpath, first_count=first_count, max_count=max_count)
dogs_list = _get_image_files(dogs_images_subpath, first_count=first_count, max_count=max_count)
img_files_list = cats_list + dogs_list
X, y = [], []
for file_path in img_files_list:
img_file_data = Image.open(file_path).convert("RGB")
X.append(img_file_data)
if 'cat' in file_path.lower():
y.append(0)
elif 'dog' in file_path.lower():
y.append(1)
return X, y
train_first_count = 0
train_max_count = training_set_count
X_train, y_train = _get_input_labels(train_first_count, train_max_count)
test_first_count = training_set_count
test_max_count = testing_set_count
X_test, y_test = _get_input_labels(test_first_count, test_max_count)
return X_train, X_test, y_train, y_testIf you are using tensor format data:
- Please note that, these tensor datasets are not fully comprising of >24k images of cats and dogs.
- Due to compute limits, a lesser subset of dataset (for example., 10k from cats and 10k from dogs) is used to create these safetensor datasets.
- Training data: Xtrain, ytrain pairs in /train.safetensor
- Testing data: Xtest, ytest pairs in /test.safetensor
