Exemplo n.º 1
0
# TODO: Implement unittests for setup.py

from setup import read_config
from setup import setup_model

config = read_config("config.json")
model, index2word, word2index = setup_model(datasets, config)
Exemplo n.º 2
0
from setup import setup
from utils import freeze_weights

# Read in command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("config_file",
                    type=str,
                    help="The path to the config file describing the model.")
parser.add_argument("--freeze",
                    action="store_true",
                    default=False,
                    help="Specifies whether the CNN layers are frozen.")
args = parser.parse_args()

# Setup the model
config = read_config(args.config_file)
_, model = setup(config)
if args.freeze:
    print("Freezing weights of CNN layers.")
    model = freeze_weights(model)

# Calculate total number of parameters and number of learnable parmaeters
num_learnable_params = 0
num_params = 0
for name, weight in model.named_parameters():
    params_in_weight = functools.reduce(operator.mul, list(weight.size()), 1)
    if weight.requires_grad:
        num_learnable_params += params_in_weight
    num_params += params_in_weight

    if weight.requires_grad:
Exemplo n.º 3
0
# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("--config_path", type=str, help="path to the config file")
parser.add_argument("--checkpoint_path", type=str, help="path to the checkpoint file")
parser.add_argument("--examples_path", type=str, help="path to examples file")
parser.add_argument("--output_dir", type=str, help="output path for generated plots")
args = parser.parse_args()

# Sanity check inputs
assert(os.path.isfile(args.config_path))
assert(os.path.isfile(args.checkpoint_path))
assert(os.path.isfile(args.examples_path))

# Read in the configuration file
print("Reading config file from: {}".format(args.config_path))
config = read_config(args.config_path)

# Create the model and overwrite its weights
print("Creating model with weights from: {}".format(args.checkpoint_path))
model = setup_model(config)
state = load_checkpoint(args.checkpoint_path)
model_dict, _, _, _ = state
model.load_state_dict(model_dict)

# Create the individual blocks of the model
use_all_layers = config["model"]["use_all_layers"]
max_length = config["model"]["max_length"]
embeddings_size = config["embeddings"]["size"]
block_configs = config["model"]["blocks"]
blocks = []
output_sizes = [embeddings_size]
Exemplo n.º 4
0
Arquivo: main.py Projeto: dzliu/ABCNN
parser.add_argument("--eval",
                    action="store_true",
                    default=False,
                    help="evaluate a model")
parser.add_argument("--path", default=None, help="path to model checkpoint")
parser.add_argument("--freeze",
                    action="store_true",
                    default=False,
                    help="freeze the weights in the conv-pool layers.")
args = parser.parse_args()

# Sanity check command line arguments
assert (args.train or args.eval)

# Basic setup
config = read_config(args.config)
datasets, model = setup_v2(config)
loss_fn = nn.CrossEntropyLoss()
optimizer = \
    optim.Adagrad(
        filter(lambda p: p.requires_grad, model.parameters()),
        lr=config["optim"]["lr"],
        weight_decay=config["optim"]["weight_decay"]
    )
history = defaultdict(list)

# Load trained model if specified
if args.path is not None:
    print("Loading model from checkpoint...")
    state = load_checkpoint(args.path)
    model_dict, optim_dict, history, epoch = state
Exemplo n.º 5
0
 def setUp(self):
     cfg = setup.read_config()
     self.nbr_address = cfg.get('nbr','address')
     print "Setup - using NBR Address: ", self.nbr_address
Exemplo n.º 6
0
        print('Starting PowerDnThread')
        pwrdnthread = PowerDnThread()
        pwrdnthread.start()


@socketio.on('connect', namespace='/test')
def test_connect():
    global thread
    if thread is None:
        thread = socketio.start_background_task(target=background_thread)
    #emit('my_response', {'data': 'Connected', 'count': 0})


@socketio.on('disconnect', namespace='/test')
def test_disconnect():
    print('Client disconnected', request.sid)


def signal_handler(signal, frame1):
    GPIO.output(2, GPIO.HIGH)
    print('Exiting after GPIO.cleanup.')
    GPIO.cleanup()
    sys.exit(0)


if __name__ == '__main__':
    signal.signal(signal.SIGINT, signal_handler)
    setup.read_config()
    setup.init_GPIO()
    socketio.run(app, host='0.0.0.0', port=5000, debug=True)
Exemplo n.º 7
0
 def __init__(self):
     Attack.__init__(self)
     JunkRemover.__init__(self)
     self.config = read_config()