Python test.test() Examples

The following are 22 code examples of test.test(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module test , or try the search function .
Example #1
Source File: main.py    From cycleGAN-PyTorch with MIT License 6 votes vote down vote up
def main():
  args = get_args()

  create_link(args.dataset_dir)

  str_ids = args.gpu_ids.split(',')
  args.gpu_ids = []
  for str_id in str_ids:
    id = int(str_id)
    if id >= 0:
      args.gpu_ids.append(id)
  print(not args.no_dropout)
  if args.training:
      print("Training")
      model = md.cycleGAN(args)
      model.train(args)
  if args.testing:
      print("Testing")
      tst.test(args) 
Example #2
Source File: prune.py    From pruning_yolov3 with GNU General Public License v3.0 6 votes vote down vote up
def prune_and_eval(model, sorted_bn, percent=.0):
        model_copy = deepcopy(model)
        thre_index = int(len(sorted_bn) * percent)
        thre = sorted_bn[thre_index]

        print(f'Gamma value that less than {thre:.4f} are set to zero!')

        remain_num = 0
        for idx in prune_idx:

            bn_module = model_copy.module_list[idx][1]

            mask = obtain_bn_mask(bn_module, thre)

            remain_num += int(mask.sum())
            bn_module.weight.data.mul_(mask)
        print("let's test the current model!")
        mAP = eval_model(model_copy)[0][2]


        print(f'Number of channels has been reduced from {len(sorted_bn)} to {remain_num}')
        print(f'Prune ratio: {1-remain_num/len(sorted_bn):.3f}')
        print(f"mAP of the 'pruned' model is {mAP:.4f}")

        return thre 
Example #3
Source File: main.py    From Policy-Gradient-and-Actor-Critic-Keras with MIT License 6 votes vote down vote up
def parse():
    parser = argparse.ArgumentParser(description="MLDS&ADL HW3")
    parser.add_argument('--env_name', default=None, help='environment name')
    parser.add_argument('--train_pg', action='store_true', help='whether train policy gradient')
    parser.add_argument('--test_pg', action='store_true', help='whether test policy gradient')
    parser.add_argument('--train_ac', action='store_true', help='wheher train Actor Critic')
    parser.add_argument('--train_pgc', action='store_true', help='wheher train PG on cart')
    parser.add_argument('--video_dir', default=None, help='output video directory')
    parser.add_argument('--do_render', action='store_true', help='whether render environment')
    parser.add_argument('--save_summary_path', type=str, default = "pg_summary/", help='')
    parser.add_argument('--save_network_path', type=str, default = "saved_pg_networks/", help='')
    try:
        from argument import add_arguments
        parser = add_arguments(parser)
    except:
        pass
    args = parser.parse_args()
    return args 
Example #4
Source File: evaluate.py    From BirdCLEF-Baseline with MIT License 6 votes vote down vote up
def evaluate():

    # Clear stats
    stats.clearStats(True)

    # Parse Dataset
    cfg.CLASSES, TRAIN, VAL = train.parseDataset()

    # Build Model
    NET = birdnet.build_model()

    # Train and return best net
    best_net = train.train(NET, TRAIN, VAL)

    # Load trained net
    SNAPSHOT = io.loadModel(best_net)

    # Test snapshot
    MLRAP, TIME_PER_EPOCH = test.test(SNAPSHOT)

    result = np.array([[MLRAP]], dtype='float32')
        
    return result 
Example #5
Source File: test_conversion.py    From vfp2py with MIT License 6 votes vote down vote up
def Test20():
    input_str = '''
REPORT FORM TEST.FRX TO PRINTER NOCONSOLE
REPORT FORM ?
'''.strip()
    output_str = '''
vfpfunc.report_form(\'test.frx\')
vfpfunc.report_form(None)
'''.strip()
    test_output_str = vfp2py.vfp2py.prg2py(input_str, 'cp1252', parser_start='lines', prepend_data='').strip()
    try:
        assert test_output_str == output_str
    except AssertionError:
        diff = difflib.unified_diff((test_output_str + '\n').splitlines(1), (output_str + '\n').splitlines(1))
        print(''.join(diff))
        raise 
Example #6
Source File: test_conversion.py    From vfp2py with MIT License 6 votes vote down vote up
def Test19():
    input_str = '''
scatter name test
scatter blank memvar
scatter to somearray
gather name test
gather memvar
gather from somearray
'''.strip()
    output_str = '''
S.test = vfpfunc.scatter(totype=\'name\')
vfpfunc.scatter(blank=True)
S.somearray = vfpfunc.scatter(totype=\'array\')
vfpfunc.gather(val=S.test)
vfpfunc.gather()
vfpfunc.gather(val=S.somearray)
'''.strip()
    test_output_str = vfp2py.vfp2py.prg2py(input_str, 'cp1252', parser_start='lines', prepend_data='').strip()
    try:
        assert test_output_str == output_str
    except AssertionError:
        diff = difflib.unified_diff((test_output_str + '\n').splitlines(1), (output_str + '\n').splitlines(1))
        print(''.join(diff))
        raise 
Example #7
Source File: test_conversion.py    From vfp2py with MIT License 6 votes vote down vote up
def Test10():
    input_str = '''
APPEND FROM TABLE_NAME
APPEND FROM TABLE_NAME TYPE DELIMITED
APPEND FROM \'table\' + \'_\' + \'name\' TYPE \'Delimited\'
APPEND FROM ARRAY TEST
'''.strip()
    output_str = '''
DB.append_from(None, \'table_name\')
DB.append_from(None, \'table_name\', filetype=\'delimited\')
DB.append_from(None, \'table_name\', filetype=\'delimited\')
DB.insert(None, S.test)
'''.strip()
    test_output_str = vfp2py.vfp2py.prg2py(input_str, 'cp1252', parser_start='lines', prepend_data='').strip()
    try:
        assert test_output_str == output_str
    except AssertionError:
        diff = difflib.unified_diff((test_output_str + '\n').splitlines(1), (output_str + '\n').splitlines(1))
        print(''.join(diff))
        raise 
Example #8
Source File: test_conversion.py    From vfp2py with MIT License 6 votes vote down vote up
def Test16():
    input_str = '''
SKIP
SKIP 10
SKIP IN TEST
SKIP someval IN TEST
'''.strip()
    output_str = '''
DB.skip(None, 1)
DB.skip(None, 10)
DB.skip(\'test\', 1)
DB.skip(\'test\', S.someval)
'''.strip()
    test_output_str = vfp2py.vfp2py.prg2py(input_str, 'cp1252', parser_start='lines', prepend_data='').strip()
    try:
        assert test_output_str == output_str
    except AssertionError:
        diff = difflib.unified_diff((test_output_str + '\n').splitlines(1), (output_str + '\n').splitlines(1))
        print(''.join(diff))
        raise 
Example #9
Source File: test_conversion.py    From vfp2py with MIT License 6 votes vote down vote up
def Test13():
    input_str = '''
PUBLIC ARRAY somearray[2, 5]
public array def[10]
SOMEARRAY(1, 4) = 3
PRIVATE TEST, somearray[2, 5]
EXTERNAL ARRAY someotherarray[3]
EXTERNAL PROCEDURE test
'''.strip()
    output_str = '''
M.add_public(somearray=Array(2, 5))
M.add_public(**{\'def\': Array(10)})
S.somearray[1, 4] = 3
M.add_private(\'test\', somearray=Array(2, 5))
# FIX ME: EXTERNAL ARRAY someotherarray[3]
# FIX ME: EXTERNAL PROCEDURE test
'''.strip()
    test_output_str = vfp2py.vfp2py.prg2py(input_str, 'cp1252', parser_start='lines', prepend_data='').strip()
    try:
        assert test_output_str == output_str
    except AssertionError:
        diff = difflib.unified_diff((test_output_str + '\n').splitlines(1), (output_str + '\n').splitlines(1))
        print(''.join(diff))
        raise 
Example #10
Source File: main.py    From Policy-Gradient-and-Actor-Critic-Keras with MIT License 5 votes vote down vote up
def run(args):
    if args.train_pg:
        env_name = args.env_name or 'Pong-v0'
        env = Environment(env_name, args)
        from agent_dir.agent_pg import Agent_PG
        agent = Agent_PG(env, args)
        agent.train()

    if args.test_pg:
        env = Environment('Pong-v0', args, test=True)
        from agent_dir.agent_pg import Agent_PG
        agent = Agent_PG(env, args)
        test(agent, env)

    # Experiment on Cartpole only, test unsupported
    if args.train_ac:
        env_name = args.env_name or 'CartPole-v0'
        env = Environment(env_name, args)
        from agent_dir.agent_actorcritic import Agent_ActorCritic
        agent = Agent_ActorCritic(env, args)
        agent.train()
    if args.train_pgc:
        env_name = args.env_name or 'CartPole-v0'
        env = Environment(env_name, args)
        from agent_dir.agent_pg_cart import Agent_PGC
        agent = Agent_PGC(env, args)
        agent.train() 
Example #11
Source File: stpn_main.py    From STPN with Apache License 2.0 5 votes vote down vote up
def main(_):
    # Parsing Arguments
    args = utils.parse_args()
    mode = args.mode
    train_iter = args.training_num
    test_iter = args.test_iter
    ckpt = utils.ckpt_path(args.ckpt)
    input_list = {
        'batch_size': args.batch_size,
        'beta': args.beta,
        'learning_rate': args.learning_rate,
        'ckpt': ckpt,
        'class_threshold': args.class_th,
        'scale': args.scale}

    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True

    tf.reset_default_graph()
    model = StpnModel()

    # Run Model
    with tf.Session(config=config) as sess:
        init = tf.global_variables_initializer()
        if mode == 'train':
            sess.run(init)
            train(sess, model, input_list, 'rgb', train_iter)  # Train RGB stream
            sess.run(init)
            train(sess, model, input_list, 'flow', train_iter)  # Train FLOW stream

        elif mode == 'test':
            sess.run(init)
            test(sess, model, init, input_list, test_iter)  # Test 
Example #12
Source File: main.py    From snip-public with MIT License 5 votes vote down vote up
def main():
    args = parse_arguments()

    # Dataset
    dataset = Dataset(**vars(args))

    # Reset the default graph and set a graph-level seed
    tf.reset_default_graph()
    tf.set_random_seed(9)

    # Model
    model = Model(num_classes=dataset.num_classes, **vars(args))
    model.construct_model()

    # Session
    sess = tf.InteractiveSession()
    tf.global_variables_initializer().run()
    tf.local_variables_initializer().run()

    # Prune
    prune.prune(args, model, sess, dataset)

    # Train and test
    train.train(args, model, sess, dataset)
    test.test(args, model, sess, dataset)

    sess.close()
    sys.exit() 
Example #13
Source File: prune.py    From yolov3-channel-and-layer-pruning with Apache License 2.0 5 votes vote down vote up
def prune_and_eval(model, sorted_bn, percent=.0):
        model_copy = deepcopy(model)
        thre_index = int(len(sorted_bn) * percent)
        thre = sorted_bn[thre_index]

        print(f'Gamma value that less than {thre:.4f} are set to zero!')

        remain_num = 0
        for idx in prune_idx:

            bn_module = model_copy.module_list[idx][1]

            mask = obtain_bn_mask(bn_module, thre)

            remain_num += int(mask.sum())
            bn_module.weight.data.mul_(mask)
        print("let's test the current model!")
        with torch.no_grad():
            mAP = eval_model(model_copy)[0][2]


        print(f'Number of channels has been reduced from {len(sorted_bn)} to {remain_num}')
        print(f'Prune ratio: {1-remain_num/len(sorted_bn):.3f}')
        print(f"mAP of the 'pruned' model is {mAP:.4f}")

        return thre 
Example #14
Source File: test_conversion.py    From vfp2py with MIT License 5 votes vote down vote up
def Test12():
    input_str = '''
LOCAL ARRAY somearray[2, 5]
LOCAL pytuple, pylist, pydict
pytuple = createobject(\'pythontuple\', \'a\', 3, .T.)
pylist = createobject(\'pythonlist\', @somearray)
pylist.callmethod(\'append\', createobject(\'pythontuple\', \'appended value\'))
pydict = createobject(\'pythondictionary\')
pydict.setitem(\'one\', 1)
?pydict.getitem(\'one\')
pythonfunctioncall(\'test\', \'test\', pytuple)
'''.strip()
    output_str = '''
M.add_local(somearray=Array(2, 5))
M.add_local(\'pytuple\', \'pylist\', \'pydict\')
S.pytuple = (\'a\', 3, True)
S.pylist = S.somearray.data[:]
S.pylist.append(\'appended value\')
S.pydict = {}
S.pydict[\'one\'] = 1
print(S.pydict[\'one\'])
test.test(*S.pytuple)
'''.strip()
    test_output_str = vfp2py.vfp2py.prg2py(input_str, 'cp1252', parser_start='lines', prepend_data='').strip()
    try:
        assert test_output_str == output_str
    except AssertionError:
        diff = difflib.unified_diff((test_output_str + '\n').splitlines(1), (output_str + '\n').splitlines(1))
        print(''.join(diff))
        raise 
Example #15
Source File: test_conversion.py    From vfp2py with MIT License 5 votes vote down vote up
def Test6():
    input_str = '''
MKDIR TEST
?DATE()
?PI()
'''.strip()
    output_str = '''
from __future__ import division, print_function

import datetime as dt
import math
import os

from vfp2py import vfpfunc
from vfp2py.vfpfunc import DB, Array, C, F, M, S, lparameters, parameters, vfpclass


@lparameters()
def MAIN():
    os.mkdir(\'test\')
    print(dt.datetime.now().date())
    print(math.pi)
'''.strip()
    test_output_str = vfp2py.vfp2py.prg2py(input_str, 'cp1252').strip()
    try:
        assert test_output_str == output_str
    except AssertionError:
        diff = difflib.unified_diff((test_output_str + '\n').splitlines(1), (output_str + '\n').splitlines(1))
        print(''.join(diff))
        raise 
Example #16
Source File: test_conversion.py    From vfp2py with MIT License 5 votes vote down vote up
def Test5():
    input_str = '''
CREAT CURSO TEST_CURSOR (SOMEFIELD N(3))
continue
LOCAL SEARCH_FOR, COUNTVAL, SUMVAL
SEARCH_FOR = \'PAUL\'
SEEK ALLTRIM(SEARCH_FOR)
COUNT FOR TEST = 3 TO COUNTVAL
SUM T * T FOR T > 0 TO SUMVAL
LOCATE WHILE X > 5 NOOPTIMIZE
RELEASE SEARCH_FOR, COUNTVAL, SUMVAL
update test set a=b, c=d, e=f where x=3
'''.strip()
    output_str = '''
DB.create_cursor(\'test_cursor\', \'somefield n(3)\', \'\')
DB.continue_locate()
M.add_local(\'search_for\', \'countval\', \'sumval\')
S.search_for = \'PAUL\'
DB.seek(None, S.search_for.strip())
S.countval = DB.count(None, (\'all\',), for_cond=lambda: S.test == 3)
S.sumval = DB.sum(None, (\'all\',), lambda: S.t * S.t, for_cond=lambda: S.t > 0)
DB.locate(nooptimize=True, while_cond=lambda: S.x > 5)
del M.search_for, M.countval, M.sumval
DB.update(\'test\', [(\'a\', S.b), (\'c\', S.d), (\'e\', S.f)], where=lambda: S.x == 3)
'''.strip()
    test_output_str = vfp2py.vfp2py.prg2py(input_str, 'cp1252', parser_start='lines', prepend_data='').strip()
    try:
        assert test_output_str == output_str
    except AssertionError:
        diff = difflib.unified_diff((test_output_str + '\n').splitlines(1), (output_str + '\n').splitlines(1))
        print(''.join(diff))
        raise 
Example #17
Source File: test_conversion.py    From vfp2py with MIT License 5 votes vote down vote up
def Test4():
    input_str = '''
LOCAL test
copy file (test) to tset
rename (test) to tset
mkdir test - test
MD test+test
rmdir (test+test)
rd alltrim(test)
!ls -al &pathname
'''.strip()
    output_str = '''
M.add_local(\'test\')
shutil.copyfile(S.test, \'tset\')
shutil.move(S.test, \'tset\')
os.mkdir(S.test - S.test)
os.mkdir(\'test+test\')
os.rmdir(S.test + S.test)
os.rmdir(S.test.strip())
vfpfunc.macro_eval(\'!ls -al &pathname\')
'''.strip()
    test_output_str = vfp2py.vfp2py.prg2py(input_str, 'cp1252', parser_start='lines', prepend_data='').strip()
    try:
        assert test_output_str == output_str
    except AssertionError:
        diff = difflib.unified_diff((test_output_str + '\n').splitlines(1), (output_str + '\n').splitlines(1))
        print(''.join(diff))
        raise 
Example #18
Source File: setup.py    From automation-hat with MIT License 5 votes vote down vote up
def run(self):
        if test is not None and test.test is not None:
            assert test.test() == True, "Automated tests failed!"
            print("notice  all tests passed: OK!")
        else:
            print("notice  automated tests skipped!") 
Example #19
Source File: setup.py    From automation-hat with MIT License 5 votes vote down vote up
def run(self):
        if test is not None and test.test is not None:
            assert test.test() == True, "Automated tests failed!"
            print("notice  all tests passed: OK!")
        else:
            print("notice  automated tests skipped!")

        build.run(self) 
Example #20
Source File: test_conversion.py    From vfp2py with MIT License 4 votes vote down vote up
def Test11():
    input_str = '''
LOCAL MYFILE, mydir
MYFILE = \'c:\\test\\test.prg\'
MYDIR = \'c:\\test\\test\\dir\'
?file(myfile)
?justdrive(MYFILE)
?justpath(MYFILE)
?justfname(MYFILE)
?juststem(myfile)
?JUSTEXT(myfile)
?FORCEEXT(myfile, \'py\')
?directory(mydir)
?justdrive(MYDIR)
?justpath(MYDIR)
?justfname(MYDIR)
?juststem(mydir)
?JUSTEXT(mydir)
?FORCEEXT(mydir, \'PY\')
?ADDBS(MYDIR) + \'dir1\'
?ADDBS(ADDBS(MYDIR) + \'dir1\') + \'dir2\'
?ADDBS(ADDBS(ADDBS(MYDIR) + \'dir1\') + \'dir2\') + \'dir3\'
?CURDIR()
RELEASE MYFILE, MYDIR
'''.strip()
    output_str = '''
M.add_local(\'myfile\', \'mydir\')
S.myfile = \'c:\\\\test\\\\test.prg\'
S.mydir = \'c:\\\\test\\\\test\\\\dir\'
print(os.path.isfile(S.myfile))
print(os.path.splitdrive(S.myfile)[0])
print(os.path.dirname(S.myfile))
print(os.path.basename(S.myfile))
print(os.path.splitext(os.path.basename(S.myfile))[0])
print(os.path.splitext(S.myfile)[1][1:])
print(os.path.splitext(S.myfile)[0] + \'.\' + \'py\')
print(os.path.isdir(S.mydir))
print(os.path.splitdrive(S.mydir)[0])
print(os.path.dirname(S.mydir))
print(os.path.basename(S.mydir))
print(os.path.splitext(os.path.basename(S.mydir))[0])
print(os.path.splitext(S.mydir)[1][1:])
print(os.path.splitext(S.mydir)[0] + \'.\' + \'py\')
print(os.path.join(S.mydir, \'dir1\'))
print(os.path.join(S.mydir, \'dir1\', \'dir2\'))
print(os.path.join(S.mydir, \'dir1\', \'dir2\', \'dir3\'))
print(os.getcwd())
del M.myfile, M.mydir
'''.strip()
    test_output_str = vfp2py.vfp2py.prg2py(input_str, 'cp1252', parser_start='lines', prepend_data='').strip()
    try:
        assert test_output_str == output_str
    except AssertionError:
        diff = difflib.unified_diff((test_output_str + '\n').splitlines(1), (output_str + '\n').splitlines(1))
        print(''.join(diff))
        raise 
Example #21
Source File: test_conversion.py    From vfp2py with MIT License 4 votes vote down vote up
def Test7():
    input_str = '''
PUSH KEY CLEAR
PUSH KEY
PUSH MENU test
PUSH POPUP test
POP KEY ALL
POP KEY
POP MENU TO MASTER test
POP POPUP test
declare integer printf in c as c_printf string
CLEAR DLLS "TEST1", "TEST2"
CLEAR MACROS
CLEAR EVENTS
CLEAR ALL
CLEAR READ
CLEAR READ ALL
CLEAR
'''.strip()
    output_str = '''
 # FIX ME: PUSH KEY CLEAR
# FIX ME: PUSH KEY
# FIX ME: PUSH MENU test
# FIX ME: PUSH POPUP test
# FIX ME: POP KEY ALL
# FIX ME: POP KEY
# FIX ME: POP MENU TO MASTER test
# FIX ME: POP POPUP test
F.dll_declare(\'c\', \'printf\', \'c_printf\')
F.dll_clear(\'test1\', \'test2\')
vfpfunc.clear(\'macros\')
vfpfunc.clear(\'events\')
vfpfunc.clear(None, \'all\')
vfpfunc.clear(\'read\')
vfpfunc.clear(\'read\', \'all\')
vfpfunc.clear(None)
'''.strip()
    test_output_str = vfp2py.vfp2py.prg2py(input_str, 'cp1252', parser_start='lines', prepend_data='').strip()
    try:
        assert test_output_str == output_str
    except AssertionError:
        diff = difflib.unified_diff((test_output_str + '\n').splitlines(1), (output_str + '\n').splitlines(1))
        print(''.join(diff))
        raise 
Example #22
Source File: test_conversion.py    From vfp2py with MIT License 4 votes vote down vote up
def Test3():
    input_str = '''
LOCAL A
DO A
DO A+B
DO A + B
DO ALLTRIM(A)
DO TEST in A
DO TEST in (A)
DO TEST IN A+\'.PRG\'
DO TEST IN A+(B)
DO TEST.PRG
DO TEST IN TEST.PRG
DO FORM SPLASH.SCX
DO FORM SPLASH.SCX NAME splashy
DO FORM SPLASH.SCX NAME splashy LINKED
CD ..
delete file test.txt
erase test.txt
delete file ?
delete file test.txt recycle
'''.strip()
    output_str = '''
M.add_local(\'a\')
F.a()
F[\'a+b\']()
F[S.a + S.b]()
F[S.a.strip()]()
a.test()
vfpfunc.module(S.a).test()
vfpfunc.module(S.a + \'.PRG\').test()
vfpfunc.module(S.a + (S.b)).test()
test.MAIN()
test.test()
vfpfunc.do_form(\'splash.scx\')
vfpfunc.do_form(\'splash.scx\', name=\'splashy\')
vfpfunc.do_form(\'splash.scx\', name=\'splashy\', linked=True)
os.chdir(\'..\')
os.remove(\'test.txt\')
os.remove(\'test.txt\')
os.remove(vfpfunc.getfile(\'\', \'Select file to\', \'Delete\', 0, \'Delete\'))
send2trash(\'test.txt\')
'''.strip()
    test_output_str = vfp2py.vfp2py.prg2py(input_str, 'cp1252', parser_start='lines', prepend_data='').strip()
    try:
        assert test_output_str == output_str
    except AssertionError:
        diff = difflib.unified_diff((test_output_str + '\n').splitlines(1), (output_str + '\n').splitlines(1))
        print(''.join(diff))
        raise