code: def k_fold(
      n_folds, dataset, batch_size, label_rate=1, val=False, seed=12345
  ):
      skf = StratifiedKFold(n_folds, shuffle=True, random_state=seed)
  
      test_indices, train_indices = [], []
      for _, idx in skf.split(
          torch.zeros(len(dataset)), dataset.data.y
      ):
          test_indices.append(torch.from_numpy(idx))
  
      if val:
          val_indices = [test_indices[i - 1] for i in range(n_folds)]
      else:
          val_indices = [test_indices[i] for i in range(n_folds)]
  
      if label_rate < 1:
          label_skf = StratifiedKFold(
              int(1.0 / label_rate), shuffle=True, random_state=seed
          )
          for i in range(n_folds):
              train_mask = torch.ones(len(dataset), dtype=torch.uint8)
              train_mask[test_indices[i].long()] = 0
              train_mask[val_indices[i].long()] = 0
              idx_train = train_mask.nonzero(as_tuple=False).view(-1)
              for _, idx in label_skf.split(
                  torch.zeros(idx_train.size()[0]),
                  dataset.data.y[idx_train],
              ):
                  idx_train = idx_train[idx]
                  break
  
              train_indices.append(idx_train)
      else:
          for i in range(n_folds):
              train_mask = torch.ones(len(dataset), dtype=torch.uint8)
              train_mask[test_indices[i].long()] = 0
              train_mask[val_indices[i].long()] = 0
              idx_train = train_mask.nonzero(as_tuple=False).view(-1)
              train_indices.append(idx_train)
  
      for i in range(n_folds):
          if batch_size is None:
              batch_size = len()
          train_loader = DataLoader(
              dataset[train_indices[i].long()], batch_size, shuffle=True
          )
          test_loader = DataLoader(
              dataset[test_indices[i].long()], batch_size, shuffle=False
          )
          val_loader = DataLoader(
              dataset[val_indices[i].long()], batch_size, shuffle=False
          )
  
          yield i, train_loader, test_loader, val_loader
  
imports: import copy
  import torch
  import numpy
  import torch.nn
  from tqdm import trange
  from sklearn.model_selection import StratifiedKFold
  from torch_geometric.loader import DataLoader
  from sklearn.svm import SVC
  from sklearn import preprocessing
  from sklearn.metrics import accuracy_score
  from sklearn.model_selection import GridSearchCV
label_desc: Use image node_id 1 for calling a global function with example usage: k_fold(n_folds, dataset, batch_size, label_rate, val, seed) without return types