code: def prepare_imagenet_subset(data_dir: Path, imagenet_dir: Path):
      print("Preparing ImageNet subset...")
      random_state = random.Random(42)
  
      # Use a predownloaded imagenet. Only validation set is used.
      imagenet = ImageNet(imagenet_dir, split="val")
      # Randomly select 10% of the data in each category
      images = defaultdict(list)
      for image_path, category_id in imagenet.imgs:
          images[category_id].append(image_path)
  
      # Target root dir
      subset_dir = data_dir / "imagenet"
      shutil.rmtree(subset_dir, ignore_errors=True)
      subset_dir.mkdir(parents=True)
      shutil.copyfile(
          imagenet_dir / "meta.bin", subset_dir / "meta.bin"
      )
      copied_count = 0
      for category_id, imgs in images.items():
          random_state.shuffle(imgs)
          for img in imgs[: len(imgs) // 10]:
              folder_name = Path(img).parent.name
              file_name = Path(img).name
              (subset_dir / "val" / folder_name).mkdir(
                  exist_ok=True, parents=True
              )
              shutil.copyfile(
                  img, subset_dir / "val" / folder_name / file_name
              )
              copied_count += 1
      print(f"Generated a subset of {copied_count} images.")
  
file_path: nni/test/vso_tools/pack_testdata.py
imports: import argparse
  import glob
  import os
  import random
  import shutil
  import subprocess
  import warnings
  from collections import defaultdict
  from pathlib import Path
  from torchvision.datasets import CIFAR10, MNIST, ImageNet
label_desc: Use image node_id 3 for calling a global function with example usage: prepare_imagenet_subset(data_dir, imagenet_dir) without return types