示例#1
0
        /// <summary>
        /// Manages the list of the latest checkpoints.
        /// </summary>
        /// <param name="latest_save_path"></param>
        private void _RecordLastCheckpoint(string latest_save_path)
        {
            if (_saver_def.MaxToKeep <= 0)
            {
                return;
            }

            // Remove first from list if the same name was used before.
            foreach (var p in _last_checkpoints)
            {
                if (latest_save_path == _CheckpointFilename((p.Key, p.Value)))
                {
                    _last_checkpoints.Remove(p.Key);
                }
            }

            // Append new path to list
            _last_checkpoints.Add(latest_save_path, Python.time());

            // If more than max_to_keep, remove oldest.
            if (_last_checkpoints.Count > _saver_def.MaxToKeep)
            {
                var first = _last_checkpoints.First();
                _last_checkpoints.Remove(first.Key);
                _checkpoints_to_be_deleted[first.Key] = first.Value;
            }
        }
示例#2
0
        private void _build(string checkpoint_path, bool build_save, bool build_restore)
        {
            if (_is_built)
            {
                return;
            }

            _is_built = true;

            if (_saver_def == null)
            {
                if (_builder == null)
                {
                    _builder = new BulkSaverBuilder(_write_version);
                }

                if (_var_list == null)
                {
                    _var_list = variables._all_saveable_objects();
                }

                if (_var_list == null || _var_list.Length == 0)
                {
                    if (_allow_empty)
                    {
                        _is_empty = true;
                        return;
                    }
                    else
                    {
                        throw new ValueError("No variables to save");
                    }
                }
                _is_empty = false;

                _saver_def = _builder._build_internal(_var_list,
                                                      reshape: _reshape,
                                                      sharded: _sharded,
                                                      max_to_keep: _max_to_keep,
                                                      keep_checkpoint_every_n_hours: _keep_checkpoint_every_n_hours,
                                                      name: _name,
                                                      restore_sequentially: _restore_sequentially,
                                                      filename: checkpoint_path,
                                                      build_save: build_save,
                                                      build_restore: build_restore);
            }
            else if (_saver_def != null && !string.IsNullOrEmpty(_name))
            {
                throw new NotImplementedException("Saver._build");
            }

            _check_saver_def();

            _next_checkpoint_time = Python.time() + _saver_def.KeepCheckpointEveryNHours * 3600;
        }