Пример #1
0
    def make_init_fn(self, chpt_path):
        if chpt_path is None:
            chpt_path = get_checkpoint_path(self.get_save_dir())
            if chpt_path is None:
                print('No checkpoint found for initialization')
                return None
            else:
                print('Initializing from previous checkpoint: {}'.format(
                    chpt_path))
        else:
            print(
                'Initializing from provided checkpoint: {}'.format(chpt_path))

        var2restore = slim.get_variables_to_restore(
            exclude=self.exclude_scopes)
        print('Variables to restore: {}'.format(
            [v.op.name for v in var2restore]))
        var2restore = remove_missing(var2restore, chpt_path)
        init_assign_op, init_feed_dict = slim.assign_from_checkpoint(
            chpt_path, var2restore)
        sys.stdout.flush()

        # Create an initial assignment function.
        def init_fn(sess):
            sess.run(init_assign_op, init_feed_dict)

        return init_fn
    def cont_init_fn(self, chpt_path):
        if chpt_path:
            if self.reinit_fc:
                var2restore = slim.get_variables_to_restore(
                    include=[
                        'encoder', 'decoder', 'generator', 'discriminator'
                    ],
                    exclude=[
                        'discriminator/fully_connected', 'discriminator/fc1',
                        'discriminator/fc2'
                    ])
            else:
                var2restore = slim.get_variables_to_restore(include=[
                    'encoder', 'decoder', 'generator', 'discriminator'
                ])
            print('Variables to restore: {}'.format(
                [v.op.name for v in var2restore]))
            var2restore = remove_missing(var2restore, chpt_path)
            init_assign_op, init_feed_dict = slim.assign_from_checkpoint(
                chpt_path, var2restore)
            sys.stdout.flush()

            # Create an initial assignment function.
            def InitAssignFn(sess):
                sess.run(init_assign_op, init_feed_dict)

            return InitAssignFn
        else:
            return None
Пример #3
0
    def make_init_fn(self, chpt_path):
        if chpt_path is None:
            return None

        var2restore = slim.get_variables_to_restore(include=['discriminator', 'generator'])

        print('Variables to restore: {}'.format([v.op.name for v in var2restore]))
        var2restore = remove_missing(var2restore, chpt_path)
        init_assign_op, init_feed_dict = slim.assign_from_checkpoint(chpt_path, var2restore)
        sys.stdout.flush()

        # Create an initial assignment function.
        def init_fn(sess):
            print('Restoring from: {}'.format(chpt_path))
            sess.run(init_assign_op, init_feed_dict)

        return init_fn
Пример #4
0
    def make_init_fn(self, chpt_path):
        # Handle model initialization from prior checkpoint
        if chpt_path is None:
            return None

        var2restore = slim.get_variables_to_restore(exclude=self.exclude_scopes)
        print('Variables to restore: {}'.format([v.op.name for v in var2restore]))
        var2restore = remove_missing(var2restore, chpt_path)
        init_assign_op, init_feed_dict = slim.assign_from_checkpoint(chpt_path, var2restore)
        sys.stdout.flush()

        # Create an initial assignment function.
        def init_fn(sess):
            print('Restoring from: {}'.format(chpt_path))
            sess.run(init_assign_op, init_feed_dict)

        return init_fn
Пример #5
0
    def make_init_fn(self, chpt_path):
        if chpt_path is None:
            ae_chpt_dir = os.path.join(
                LOG_DIR, '{}_{}/'.format(self.model.ae.name,
                                         self.dataset.name))
            chpt_path = get_checkpoint_path(ae_chpt_dir)

        var2restore = slim.get_variables_to_restore(
            include=self.restore_scopes)
        print('Variables to restore: {}'.format(
            [v.op.name for v in var2restore]))
        var2restore = remove_missing(var2restore, chpt_path)
        init_assign_op, init_feed_dict = slim.assign_from_checkpoint(
            chpt_path, var2restore)
        sys.stdout.flush()

        # Create an initial assignment function.
        def init_fn(sess):
            print('Restoring from: {}'.format(chpt_path))
            sess.run(init_assign_op, init_feed_dict)

        return init_fn