Man1103/ResNet18-FT-PetImages-11.7M
Image Classification • 11.7M • Updated • 1
The dataset viewer is not available because its heuristics could not detect any supported data files. You can try uploading some data files, or configuring the data files location manually.
This is clone of popular Cats Vs. Dogs image classification dataset for CNN-based visual classification models.
/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_test