Ejemplo n.º 1
0
 def test_get_logger_no_duplicate_handlers(self, mock_read_config):
     config = self.config.copy()
     # No duplicate hanlders
     mock_read_config.return_value = config
     logger = get_logger()
     number_of_handlers = len(logger.handlers)
     logger = get_logger()
     self.assertEqual(len(logger.handlers), number_of_handlers)
Ejemplo n.º 2
0
 def test_get_logger_no_config(self, mock_read_config):
     config = self.config.copy()
     # Add null handler if not configured
     del config["app"]["logger"]
     mock_read_config.return_value = config
     logger = get_logger()
     self.assertTrue(
         len([h for h in logger.handlers if isinstance(h, logging.NullHandler)]) > 0
     )
Ejemplo n.º 3
0
import torch
import torch.utils.data

import tqdm

from src import config, get_logger, round_probabilities, Dataset, get_metrics

logger = get_logger()

logger.info("Loading train dataset")
trainDataset = Dataset(config["path_to_processed_MAPS"], "train")
trainDatasetMean = trainDataset.mean()

logger.info("Loading test dataset")
testDataset = Dataset(config["path_to_processed_MAPS"], "test")

dataloader = torch.utils.data.DataLoader(testDataset, batch_size=config["mini_batch_size"], shuffle=True)

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = torch.load("./models/Dnn3Layers/095.pth")
model = model.to(device)
model = model.eval()

testMetrics = {}

for batchX, batchy in tqdm.tqdm(dataloader):
	batchX -= trainDatasetMean
	batchX = batchX.to(device)
	batchy = batchy.to(device)

	prediction = round_probabilities(model(batchX))
Ejemplo n.º 4
0
 def test_get_logger(self, mock_read_config):
     config = self.config.copy()
     # success flow
     mock_read_config.return_value = config
     logger = get_logger()
     self.assertTrue(len(logger.handlers) > 1)
Ejemplo n.º 5
0
import os
import re

from src import get_logger
from src.annict import Annict
from src.utils import get_today
from src.aws.sns import SNS

SNS_TOPIC = os.getenv("SNS_TOPIC_ARN")

logger = get_logger(__name__)


def handler(event, context):
    annict = Annict()

    programs: dict = annict.get_episodes()
    today_animes: dict = annict.get_stream_episode_specified_date(
        watch_date=get_specified_date(event), programs=programs)
    sns = SNS()
    sns.send_message(topic_arn=SNS_TOPIC,
                     message=create_notify_message(today_animes))


def get_specified_date(event):
    is_matched = False

    if event.get('s_date'):
        # Only 0000-00-00 that is date.
        is_matched = re.match(r"\d{4}-\d{2}-\d{2}", event.get('s_date'))
Ejemplo n.º 6
0
                    default='./output.midi')

args = parser.parse_args()

# Start generating midi workflow
class SongDataset(torch.utils.data.Dataset):
    def __init__(self, X):
        self._X = X

    def __len__(self):
        return self._X.size()[0]

    def __getitem__(self, index):
        return self._X[index]

logger = get_logger(file_silent=True)

logger.info("Performing cqt")
X = cqt(args.wav)
logger.info("Done")

logger.info("Loading model")

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = torch.load(os.path.join(config["public_models_folder"], args.model))
model = model.to(device)
model = model.eval()

X = torch.from_numpy(X).float()

trainDatasetMeans = torch.load(os.path.join(config["public_models_folder"], "train_means.pth"))