<commit_before>from __future__ import division
import abc

from serializablecallable import SerializableCallable


class Unified(object):

    __metaclass__ = abc.ABCMeta

    def __getstate__(self):
        import menpofast.feature as menpofast_feature
        d = self.__dict__.copy()

        features = d.pop('features')
        if self.pyramid_on_features:
            # features is a single callable
            d['features'] = SerializableCallable(features, [menpofast_feature])
        else:
            # features is a list of callables
            d['features'] = [SerializableCallable(f, [menpofast_feature])
                             for f in features]
        return d

    def __setstate__(self, state):
        try:
            state['features'] = state['features'].callable
        except AttributeError:
            state['features'] = [f.callable for f in state['features']]
        self.__dict__.update(state)

    @property
    def n_levels(self):
        """
        The number of scale levels of the AAM.

        :type: `int`
        """
        return len(self.scales)


class GlobalUnified(Unified):

    def __init__(self, shape_models, appearance_models, classifiers,
                 reference_shape, transform, parts_shape, features,
                 normalize_parts, sigma, scales, scale_shapes, scale_features):
        self.shape_models = shape_models
        self.appearance_models = appearance_models
        self.classifiers = classifiers
        self.reference_shape = reference_shape
        self.transform = transform
        self.parts_shape = parts_shape
        self.features = features<commit_msg>Fix getstate and setstate for unified model<commit_after>from __future__ import division
import abc

from serializablecallable import SerializableCallable


class Unified(object):

    __metaclass__ = abc.ABCMeta

    def __getstate__(self):
        import menpofast.feature as menpofast_feature
        d = self.__dict__.copy()

        features = d.pop('features')
        d['features'] = SerializableCallable(features, [menpofast_feature])

        return d

    def __setstate__(self, state):
        state['features'] = state['features'].callable
        self.__dict__.update(state)

    @property
    def n_levels(self):
        """
        The number of scale levels of the AAM.

        :type: `int`
        """
        return len(self.scales)


class GlobalUnified(Unified):

    def __init__(self, shape_models, appearance_models, classifiers,
                 reference_shape, transform, parts_shape, features,
                 normalize_parts, sigma, scales, scale_shapes, scale_features):
        self.shape_models = shape_models
        self.appearance_models = appearance_models
        self.classifiers = classifiers
        self.reference_shape = reference_shape
        self.transform = transform
        self.parts_shape = parts_shape
        self.features = features
{'fraction_non_alphanumeric': 0.07957650273224044, 'fraction_numerical': 0.0, 'mean_word_length': 2.5503030303030303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1858424', 'n_tokens_mistral': 800, 'n_tokens_neox': 773, 'n_words': 195}