You can make your batch_size=1 and skip everything other than specific classes during the training loop. Maybe it’s not the most efficient but it’s very easy:
classes: list[str] = sorted(os.listdir(datadir))
targets: list[int] = [classes.index(label) for label in classes if label in ('Dog','Cat')]

for epoch in tqdm(range(epochs)):
	for images, labels in tqdm(trainloader):
		if not any(x in labels for x in targets):
			continue