My function doesn't work def evaluate(model, dataloader, dataset, numbatches):…
- User
My function doesn't work
def evaluate(model, dataloader, dataset, num_batches): model.eval() batch_count = 0
codeforecasts = [] forecasts_mean = [] forecasts_scale = [] forecasts_dof = model.config.dof for batch in tqdm(dataloader): with torch.no_grad(): outputs = model.generate( static_categorical_features=batch["static_categorical_features"].to(device) if config.num_static_categorical_features > 0 else None, static_real_features=batch["static_real_features"].to(device) if config.num_static_real_features > 0 else None, past_time_features=batch["past_time_features"].to(device), past_values=batch["past_values"].to(device), future_time_features=batch["future_time_features"].to(device), past_observed_mask=batch["past_observed_mask"].to(device), ) forecasts.append(outputs.sequences.cpu().numpy()) batch_count += 1 if batch_count >= num_batches: break forecasts = np.vstack(forecasts) print(forecasts.shape) forecasts_mean.append(np.mean(forecasts, axis=1)) forecasts_scale.append(np.std(forecasts, axis=1)) batch_count += 1 if batch_count >= num_batches: break forecasts_mean = np.vstack(forecasts_mean) print(forecasts_mean.shape) forecasts_scale = np.vstack(forecasts_scale) print(forecasts_scale.shape) nll_metrics = [] last_index = num_batches * batch_size count_idx = 0 for item_id, ts in tqdm(enumerate(dataset)): ground_truth = ts["target"][-prediction_length:] predicted_mean = forecasts_mean[item_id] predicted_scale = forecasts_scale[item_id] nll = negative_log_likelihood_student_t( torch.tensor(predicted_mean), torch.tensor(ground_truth), torch.tensor(predicted_scale), torch.tensor(forecasts_dof) ) nll_metrics.append(nll) count_idx += 1 if count_idx >= last_index: break return np.mean(nll_metrics) - Assistant
- User
this is error in console
(64, 100, 64) (64, 64) (64, 64) 64/? [00:00<00:00, 2488.92it/s]
IndexError Traceback (most recent call last) Cell In[50], line 65 62 print("Не найдена лучшая модель в директории") 64 print(f'Старт обучения модели на датафрейме в папке {work_signals_path} с файлом {filename}') ---> 65 train_model(num_epoch, num_val_batches, train_dataloader, val_dataloader, dataset['validation'], best_model_path, filename) 66 # train_model_with_replay_and_ewc(num_epoch, 67 # num_val_batches, 68 # train_dataloader, (...) 74 # global_lower_bound, 75 # global_upper_bound) 76 print(f'Закончено обучения модели на датафрейме в папке {work_signals_path} с файлом № {filename}')
- Assistant
- User
- Assistant
- User
so i can decrease it to some custom level, like 30 or maybe lower if i want that model predict with more struggle conditions
- Assistant