Read git diff upstream/main to see the changes in this branch. Now change…
- User
Read
git diff upstream/mainto see the changes in this branch. Now changeskip_image_resolutionto a tuple, and allow the user to input either a number or a tuple, like howresolutionis handled. Assistant
Now let me look at how
resolutionis handled in the relevant files:Assistant
Now let me read the argparse and resolution parsing sections of
train_util.py:Assistant
Now let me look at the
DreamBoothDataset,FineTuningDataset, andControlNetDatasetsignatures:Assistant
Now let me look at the argparse declaration for
skip_image_resolutionand theBaseDatasetinit:Assistant
Let me check the ControlNetDataset's skip_image_resolution check:
Assistant
Now let me look at how the dataset is constructed from blueprint in
config_util.py:Assistant
Now I have a full picture. Let me set up the todos and make all the changes:
Assistant
1.
BaseDataset.__init__signature:Assistant
2.
check_orig_resolution— compute threshold from tuple:Assistant
3.
filter_registered_images_by_orig_resolution:== 0→is None:Assistant
4. Update
DreamBoothDataset,FineTuningDataset, andControlNetDatasetsignatures:Assistant
5.
ControlNetDataset!= 0→is not None:Assistant
6. Update argparse declaration (
type=float, default=0.0→type=str, default=None):Assistant
7. Add
skip_image_resolutiontuple parsing inverify_training_args(right after theresolutionparsing block):Assistant
8. Update
config_util.py—BaseDatasetParamstype and schema validator:Assistant
Let me do a quick sanity check to verify all the changes look correct:
Assistant
All changes look correct. Here's a summary of everything that was updated:
library/train_util.py:BaseDataset.__init__:skip_image_resolution: float = 0.0→Optional[Tuple[int, int]] = Nonecheck_orig_resolution: computesthreshold = math.sqrt(self.skip_image_resolution[0] * self.skip_image_resolution[1])and compares against itfilter_registered_images_by_orig_resolution:== 0→is NoneDreamBoothDataset.__init__:Optional[float] = None→Optional[Tuple[int, int]] = NoneFineTuningDataset.__init__: sameControlNetDataset.__init__:float = 0.0→Optional[Tuple[int, int]] = NoneControlNetDatasetconditioning check: →
- User
Can we move the filtering of original resolution from make_buckets to init ? Does it mean we don't need to rebalance regularization images and we can simplify the changes in this branch?
Assistant
Let me read the relevant code to understand the full flow before answering:
Assistant
Let me trace the full DreamBooth
__init__and image registration flow:- User
Do you think we can add the code like
codeif self.skip_image_resolution is not None: filtered_img_paths = [] filtered_sizes = [] skip_image_area = self.skip_image_resolution[0] * self.skip_image_resolution[1] for img_path, size in zip(img_paths, sizes): if size is None: # no latents cache file, get image size by reading image file (slow) size = self.get_image_size(img_path) if size[0] * size[1] <= skip_image_area: continue filtered_img_paths.append(img_path) filtered_sizes.append(size) img_paths = filtered_img_paths sizes = filtered_sizes # add some logging herebefore the validation split? For now we use
get_image_sizeif the size is not already known, and we aim to simplify the diff betweeen upstream/main and this branch. Assistant
Let me read the full
ControlNetDataset.__init__to understand the conditioning image check order:Assistant
Let me also read the FineTuningDataset
__init__to get the full picture:Assistant
Now I have the full picture. Let me answer your question before implementing anything.
Yes, and yes — this approach works and eliminates the rebalancing entirely. Here's why:
In
DreamBoothDataset.__init__, the flow is:load_dreambooth_dirruns per subset → producesimg_paths/sizes- Validation split
- Training images registered →
num_train_imagesaccumulated - Reg images collected into
reg_infos - balances reg images to match training count
- User
Do it
Assistant
Let me read all the exact code I need to touch in one pass:
Assistant
Step 1: Remove
check_orig_resolution,update_dataset_image_counts,filter_registered_images_by_orig_resolutionfromBaseDataset:Assistant
Step 2: Remove the three
DreamBoothDatasetmethods and revert the call site back to the original inline loop:Assistant
Now revert the
register_regularization_imagescall back to the original inline loop:Assistant
Step 3: Remove the filter call from
BaseDataset.make_buckets:Assistant
Step 4: Add the filter in
load_dreambooth_dirbefore the validation split:Assistant
Step 5: Add the filter in
FineTuningDataset.__init__beforeregister_image, and fix up counts:Assistant
Now add the filter check before
register_imageand fix up counts after the loop:Assistant
Now add the logging after the loop:
Assistant
Step 6: Simplify
ControlNetDataset.__init__conditioning check — restore original assert for missing, warn for extra:Assistant
Step 7: Remove the extra
missing_imgscheck fromControlNetDataset.make_buckets:Assistant
Let me do a final sanity check on the diff:
Assistant
The diff looks clean. Here's a summary of what changed:
Removed entirely from the diff vs upstream/main:
BaseDataset.check_orig_resolutionBaseDataset.update_dataset_image_countsBaseDataset.filter_registered_images_by_orig_resolutionDreamBoothDataset.register_regularization_images(extracted method — back to inline loop)DreamBoothDataset.rebalance_regularization_imagesDreamBoothDataset.filter_registered_images_by_orig_resolution- The filter call + size-loading loop in
make_buckets - The extra
missing_imgsre-check inControlNetDataset.make_buckets - The
skip_image_resolution != 0branch inControlNetDataset.__init__
What remains:
skip_image_resolutionstored asOptional[Tuple[int, int]]onBaseDataset
- User
When FineTuningDataset.init , when we do the filtering, do we use the image size from metadata if possible?
Assistant
Yes. The filter at lines 2392–2400 reads
image_info.image_size, which is already set from metadata (image_sizefield, lines 2383–2385) or from the npz cache filename (lines 2386–2390) before the filter runs.get_image_size(slow file read) is only called as a last resort whenimage_info.image_sizeis stillNone.One minor cleanup though — the outer
skip_image_areavariable I added before the loop is now unused since the inner code recomputes it. Let me fix that:Assistant
Yes — the order is:
image_sizefrom metadata JSON →image_info.image_sizesetimage_sizefrom npz cache filename →image_info.image_sizeset- Filter check reads
image_info.image_size— only callsget_image_size()(slow file read) if stillNone
Also took the opportunity to hoist
skip_image_areaout of the per-image loop (it was being recomputed on every iteration) into the pre-loop setup where it already lived.