tfutils.tests package

Submodules

tfutils.tests.test_base module

Test base module.

class tfutils.tests.test_base.TestBase(methodName='runTest')[source]

Bases: unittest.case.TestCase

assert_as_expected(exp_id, count=None, step=None)[source]
assert_count(exp_id, count)[source]
assert_step(exp_id, step)[source]
static asserts_for_record(r, params, train=False)[source]
static custom_train_loop(sess, train_targets, **loop_params)[source]

Define Custom training loop.

Parameters:
  • sess (tf.Session) – Current tensorflow session.
  • train_targets (list) – Description.
  • **loop_params – Optional kwargs needed to perform custom train loop.
Returns:

A dictionary containing train targets evaluated by the session.

Return type:

dict

database_name = '_tfutils'
static get_extraction_target(inputs, outputs, to_extract, **loss_params)[source]

Produce validation target function.

Example validation target function to use to provide targets for extracting features. This function also adds a standard “loss” target which you may or not may not want

The to_extract argument must be a dictionary of the form
{name_for_saving: name_of_actual_tensor, …}

where the “name_for_saving” is a human-friendly name you want to save extracted features under, and name_of_actual_tensor is a name of the tensor in the tensorflow graph outputing the features desired to be extracted. To figure out what the names of the tensors you want to extract are “to_extract” argument, uncomment the commented-out lines, which will print a list of all available tensor names.

static get_first_image_target(inputs, outputs, **ttarg_params)[source]

Return target for saving the first image of every batch.

Used in test_training_save test to test save_to_gfs option.

host = 'localhost'
static makedirs(dir)[source]
port = 29101
classmethod remove_collection(collection_name)[source]

Remove a MonogoDB collection.

classmethod remove_database(database_name)[source]

Remove a MonogoDB database.

classmethod remove_directory(directory)[source]

Remove a directory.

classmethod remove_document(document)[source]
setUp()[source]

Set up class before each test method is executed.

classmethod setUpClass()[source]

Set up class once before any test methods are run.

setup_params(exp_id)[source]

Specify training params with a specific exp_id.

tearDown()[source]

Tear Down is called after each test method is executed.

classmethod tearDownClass()[source]

Tear down class after all test methods have run.

test_custom_training()[source]

Illustrate training with custom training loop.

This test illustrates how basic training is performed with a custom training loop using the tfutils.base.train_from_params function.

test_feature_extraction()[source]

Illustrate feature extraction.

This is a test illustrating how to perform feature extraction using tfutils.base.test_from_params. The basic idea is to specify a validation target that is simply the actual output of the model at some layer. (See the “get_extraction_target” function above as well.) This test assumes that test_train has run first.

After the test is run, the results of the feature extraction are saved in the Grid File System associated with the mongo database, with one file per batch of feature results. See how the features are accessed by reading the test code below.

test_training()[source]

Illustrate training.

This test illustrates how basic training is performed using the tfutils.base.train_from_params function. This is the first in a sequence of interconnected tests. It creates a pretrained model that is used by the next few tests (test_validation and test_feature_extraction).

As can be seen by looking at how the test checks for correctness, after the training is run, results of training, including (intermittently) the full variables needed to re-initialize the tensorflow model, are stored in a MongoDB.

Also see docstring of the tfutils.base.train_from_params function for more detailed information about usage.

test_training_save()[source]

Illustrate saving to the grid file system during training time.

test_validation()[source]

Illustrate validation.

This is a test illustrating how to compute performance on a trained model on a new dataset, using the tfutils.base.test_from_params function. This test assumes that test_training function has run first (to provide a pre-trained model to validate).

After the test is run, results from the validation are stored in the MongoDB. (The test shows how the record can be loaded for inspection.)

See the docstring of tfutils.base.test_from_params for more detailed information on usage.

class tfutils.tests.test_base.TestDistributedModel(methodName='runTest')[source]

Bases: tfutils.tests.test_base.TestBase

setup_params(exp_id)[source]

Specify training params with a specific exp_id.

class tfutils.tests.test_base.TestDistributedMulti(methodName='runTest')[source]

Bases: tfutils.tests.test_base.TestMultiModel

setup_params(exp_id)[source]

Specify training params with a specific exp_id.

class tfutils.tests.test_base.TestMultiModel(methodName='runTest')[source]

Bases: tfutils.tests.test_base.TestBase

setup_params(exp_id)[source]

Specify training params with a specific exp_id.

test_training()[source]

Illustrate training.

This test illustrates how basic training is performed using the tfutils.base.train_from_params function. This is the first in a sequence of interconnected tests. It creates a pretrained model that is used by the next few tests (test_validation and test_feature_extraction).

As can be seen by looking at how the test checks for correctness, after the training is run, results of training, including (intermittently) the full variables needed to re-initialize the tensorflow model, are stored in a MongoDB.

Also see docstring of the tfutils.base.train_from_params function for more detailed information about usage.

test_training_save()[source]

Illustrate saving to the grid file system during training time.

test_validation()[source]

Illustrate validation.

This is a test illustrating how to compute performance on a trained model on a new dataset, using the tfutils.base.test_from_params function. This test assumes that test_training function has run first (to provide a pre-trained model to validate).

After the test is run, results from the validation are stored in the MongoDB. (The test shows how the record can be loaded for inspection.)

See the docstring of tfutils.base.test_from_params for more detailed information on usage.

tfutils.tests.test_base.setUpModule()[source]

Set up module once, before any TestCases are run.

tfutils.tests.test_base.tearDownModule()[source]

Tear down module after all TestCases are run.

tfutils.tests.test_dbinterface module

Test DBInterface.

class tfutils.tests.test_dbinterface.TestDBInterface(methodName='runTest')[source]

Bases: unittest.case.TestCase

CACHE_DIR = 'TFUTILS_TEST_CACHE_DIR'
COLLECTION_NAME = 'TFUTILS_TESTCOL'
DATABASE_NAME = 'TFUTILS_TESTDB'
EXP_ID = 'TEST_EXP_ID'
HOST = 'localhost'
PORT = 29101
load_test_checkpoint(save_path)[source]
static makedirs(dir)[source]
classmethod remove_checkpoint(checkpoint)[source]

Remove a tf.train.Saver checkpoint.

classmethod remove_collection(collection_name)[source]

Remove a MonogoDB collection.

classmethod remove_database(database_name)[source]

Remove a MonogoDB database.

classmethod remove_directory(directory)[source]

Remove a directory.

classmethod remove_document(document)[source]
save_test_checkpoint()[source]
setUp()[source]

Set up class before _each_ test method is executed.

Creates a tensorflow session and instantiates a dbinterface.

classmethod setUpClass()[source]

Set up class once before any test methods are run.

classmethod setup_cache()[source]
classmethod setup_conn()[source]
classmethod setup_log()[source]
setup_model(weights_name='Weights', bias_name='Bias')[source]

Set up simple tensorflow model.

classmethod setup_params()[source]
tearDown()[source]

Tear Down is called after _each_ test method is executed.

classmethod tearDownClass()[source]

Tear down class after all test methods have run.

test_filter_var_list()[source]
test_get_restore_vars()[source]
test_init(**kwargs)[source]
test_initialize(**kwargs)[source]
test_initialize_from_ckpt(**kwargs)[source]
test_load_from_db(**kwargs)[source]
test_load_rec(**kwargs)[source]
test_remap_var_list()[source]
test_save(**kwargs)[source]
test_save_thread(**kwargs)[source]
test_sync_with_host(**kwargs)[source]
test_tf_saver(**kwargs)[source]
train_model(num_steps=100)[source]
tfutils.tests.test_dbinterface.setUpModule()[source]

Set up module once, before any TestCases are run.

tfutils.tests.test_dbinterface.tearDownModule()[source]

Tear down module after all TestCases are run.

Module contents