mirror of
https://github.com/gryf/coach.git
synced 2026-02-21 01:05:50 +01:00
Tf checkpointing using saver mechanism (#134)
This commit is contained in:
committed by
Gal Leibovich
parent
dd18959e53
commit
16cdd9a9c1
@@ -1,21 +1,17 @@
|
||||
import os
|
||||
import pytest
|
||||
import tempfile
|
||||
|
||||
from rl_coach import utils
|
||||
|
||||
|
||||
@pytest.mark.unit_test
|
||||
def test_get_checkpoint_state_default():
|
||||
files = ['4.test.ckpt.ext', '2.test.ckpt.ext', '3.test.ckpt.ext', '1.test.ckpt.ext']
|
||||
checkpoint_state = utils.get_checkpoint_state(files)
|
||||
assert checkpoint_state.model_checkpoint_path == '4.test.ckpt'
|
||||
assert checkpoint_state.all_model_checkpoint_paths == [f[:-4] for f in sorted(files)]
|
||||
|
||||
|
||||
@pytest.mark.unit_test
|
||||
def test_get_checkpoint_state_custom():
|
||||
files = ['prefix.4.test.ckpt.ext', 'prefix.2.test.ckpt.ext', 'prefix.3.test.ckpt.ext', 'prefix.1.test.ckpt.ext']
|
||||
assert len(utils.get_checkpoint_state(files).all_model_checkpoint_paths) == 0 # doesn't match the default pattern
|
||||
checkpoint_state = utils.get_checkpoint_state(files, filename_pattern=r'([0-9]+)[^0-9].*?\.ckpt')
|
||||
assert checkpoint_state.model_checkpoint_path == '4.test.ckpt'
|
||||
assert checkpoint_state.all_model_checkpoint_paths == [f[7:-4] for f in sorted(files)]
|
||||
def test_get_checkpoint_state():
|
||||
files = ['4.test.ckpt.ext', '2.test.ckpt.ext', '3.test.ckpt.ext', '1.test.ckpt.ext', 'prefix.10.test.ckpt.ext']
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
[open(os.path.join(temp_dir, fn), 'a').close() for fn in files]
|
||||
checkpoint_state = utils.get_checkpoint_state(temp_dir)
|
||||
assert checkpoint_state.model_checkpoint_path == os.path.join(temp_dir, '4.test.ckpt')
|
||||
assert checkpoint_state.all_model_checkpoint_paths == \
|
||||
[os.path.join(temp_dir, f[:-4]) for f in sorted(files[:-1])]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user