import numpy as np import yaml import pickle from scipy.optimize import minimize import torch from torch import nn from torch.utils.data import DataLoader from torch.cuda.amp import autocast from mykaggle.util.logger import get_logger from mykaggle.model.model import get_model from mykaggle.trainer.base import Mode from mykaggle.dataloader.dataloader import get_dataloader from mykaggle.dataloader.dataset import get_dataset LOGGER = get_logger(__name__) def predict(model: nn.Module, df: pd.DataFrame, dataloader: DataLoader, batch_size: int, num_classes: int, use_amp: bool = True) -> np.ndarray: if num_classes > 1: preds = np.zeros((len(df), num_classes), dtype=np.float32) else: preds = np.zeros((len(df)), dtype=np.float32) device = torch.device('cuda') model.to(device) model.eval()
from typing import Any, List, Dict, Optional import time import pandas as pd from mykaggle.feature.base import Feature from mykaggle.util.logger import get_logger logger = get_logger(__name__) class FeatureFactory: @classmethod def run(cls, names: List[str], params: Dict[str, Dict[str, Any]], base: pd.DataFrame, others: pd.DataFrame, train: bool, use_cache: bool = False, save_cache: bool = False) -> pd.DataFrame: ''' 与えられた特徴の名前とパラメータのリストから train/test の特徴を作って返す ''' features = cls.get_features(names, params, train=train) df = cls.create_feature(features, base, others, use_cache, save_cache, params) return df @classmethod def get_features(cls, names: List[str], params: Dict[str, Dict[str, Any]], train: bool) -> List[Feature]: '''