# Path: kraken/lib/models.py
# class TorchSeqRecognizer(object):
#     def __init__(self, nn: TorchVGSLModel, decoder=kraken.lib.ctc_decoder.greedy_decoder, train: bool = False, device: str = 'cpu'):
#     def to(self, device):
#     def forward(self, line: torch.Tensor, lens: torch.Tensor = None) -> Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]:
#     def predict(self, line: torch.Tensor, lens: Optional[torch.Tensor] = None) -> List[List[Tuple[str, int, int, float]]]:
#     def predict_string(self, line: torch.Tensor, lens: Optional[torch.Tensor] = None) -> List[str]:
#     def predict_labels(self, line: torch.tensor, lens: torch.Tensor = None) -> List[List[Tuple[int, int, int, float]]]:
# def load_any(fname: str, train: bool = False, device: str = 'cpu') -> TorchSeqRecognizer:
# def validate_hyper_parameters(hyper_params):
# 
# Path: kraken/lib/exceptions.py
# class KrakenInvalidModelException(Exception):
# 
#     def __init__(self, message=None):
#         Exception.__init__(self, message)


import os
import pickle
import unittest
import tempfile
import kraken.lib.lstm
from pytest import raises
from pathlib import Path
from kraken.lib import models
from kraken.lib.exceptions import KrakenInvalidModelException
        self.temp.close()
        os.unlink(self.temp.name)

    def test_load_invalid(self):
        """
        Tests correct handling of invalid files.
        """
        with raises(KrakenInvalidModelException):
            models.load_any(self.temp.name)

    def test_load_clstm(self):
        """
        Tests loading of valid clstm files.
        """
        rnn = models.load_any(resources / 'toy.clstm')
        self.assertIsInstance(rnn, models.TorchSeqRecognizer)

    def test_load_pyrnn_no_seqrecognizer(self):
        """
        Test correct handling of non-SeqRecognizer pickles.
        """
        pickle.dump(u'Iámnõtãrécðçnízer', self.temp)
        self.temp.close()
        with raises(KrakenInvalidModelException):
            models.load_any(self.temp.name)

    def test_load_any_pyrnn_py3(self):
        """
        Test load_any doesn't load pickled models on python 3
        """

# Path: kraken/lib/models.py
# class TorchSeqRecognizer(object):
#     def __init__(self, nn: TorchVGSLModel, decoder=kraken.lib.ctc_decoder.greedy_decoder, train: bool = False, device: str = 'cpu'):
#     def to(self, device):
#     def forward(self, line: torch.Tensor, lens: torch.Tensor = None) -> Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]:
#     def predict(self, line: torch.Tensor, lens: Optional[torch.Tensor] = None) -> List[List[Tuple[str, int, int, float]]]:
#     def predict_string(self, line: torch.Tensor, lens: Optional[torch.Tensor] = None) -> List[str]:
#     def predict_labels(self, line: torch.tensor, lens: torch.Tensor = None) -> List[List[Tuple[int, int, int, float]]]:
# def load_any(fname: str, train: bool = False, device: str = 'cpu') -> TorchSeqRecognizer:
# def validate_hyper_parameters(hyper_params):
# 
# Path: kraken/lib/exceptions.py
# class KrakenInvalidModelException(Exception):
# 
#     def __init__(self, message=None):
#         Exception.__init__(self, message)


# Path: tests/test_models.py
import os
import pickle
import unittest
import tempfile
import kraken.lib.lstm
from pytest import raises
from pathlib import Path
from kraken.lib import models
from kraken.lib.exceptions import KrakenInvalidModelException

        self.temp.close()
        os.unlink(self.temp.name)

    def test_load_invalid(self):
        """
        Tests correct handling of invalid files.
        """
        with raises(KrakenInvalidModelException):
            models.load_any(self.temp.name)

    def test_load_clstm(self):
        """
        Tests loading of valid clstm files.
        """
        rnn = models.load_any(resources / 'toy.clstm')
        self.assertIsInstance(rnn, models.TorchSeqRecognizer)

    def test_load_pyrnn_no_seqrecognizer(self):
        """
        Test correct handling of non-SeqRecognizer pickles.
        """
        pickle.dump(u'Iámnõtãrécðçnízer', self.temp)
        self.temp.close()
        with raises(KrakenInvalidModelException):
            models.load_any(self.temp.name)

    def test_load_any_pyrnn_py3(self):
        """
        Test load_any doesn't load pickled models on python 3
        """

        with raises(KrakenInvalidModelException):