def _load_model(hyperparams):
     if isinstance(hyperparams, RMTPPHyperParams):
         model = RMTPP(hyperparams)
     elif isinstance(hyperparams, Model1HyperParams):
         model = Model1.from_model_hyperparams(hyperparams)
     elif isinstance(hyperparams, Model2HyperParams):
         model = Model2.from_model_hyperparams(hyperparams)
     # elif isinstance(hyperparams, Model2FilterHyperParams):
     #     model = Model2Filter.from_model_hyperparams(hyperparams)
     else:
         raise ValueError("Did not specify model name correctly")
     return model
Example #2
0
class Controller1:
    def __init__(self):
        self.model = Model()  # binding instances
        self.view = View(self)  # pass controller instance to view

    def main(self):
        print('Controller1.main executed...')
        self.view.main()  # run View's main (will call infinite loop!)

    def on_button_click(self):
        result = self.model.update_counter()
        self.view.value_var.set(result)
        self.view.update_button()
Example #3
0
    def __init__(self):
        super().__init__()
        self.model1 = Model1()
        self.model2_testreport = Model2_TestReport()
        self.model2_testinstruction = Model2_TestInstruction()
        self.model2_bug = Model2_Bug()

        #绑定转换成word页面向导
        self.sltColumn_ui = ui_selectcolumn.Ui_WizardPage()
        self.sltColumn_ui.setupUi(self)

        #绑定模板1
        model1Page = QWidget(self.sltColumn_ui.tab)

        self.model1.model1_ui.setupUi(model1Page)
        self.sltColumn_ui.gridLayout_3.addWidget(model1Page)

        #绑定模板2-测试报告
        model2_testreportPage = QWidget(self.sltColumn_ui.tab_4)

        self.model2_testreport.model2_testreport_ui.setupUi(
            model2_testreportPage)
        self.sltColumn_ui.gridLayout_5.addWidget(model2_testreportPage)

        #绑定模板2-测试说明
        model2_testinstructionPage = QWidget(self.sltColumn_ui.tab_2)

        self.model2_testinstruction.model2_testinstruction_ui.setupUi(
            model2_testinstructionPage)
        self.sltColumn_ui.gridLayout_4.addWidget(model2_testinstructionPage)

        #绑定模板2-bug
        model2_bugPage = QWidget(self.sltColumn_ui.tab_5)

        self.model2_bug.model2_bug_ui.setupUi(model2_bugPage)
        self.sltColumn_ui.gridLayout_6.addWidget(model2_bugPage)
Example #4
0
# Setting up training parameters
max_num_training_steps = config['max_num_training_steps']
num_output_steps = config['num_output_steps']
num_summary_steps = config['num_summary_steps']
num_checkpoint_steps = config['num_checkpoint_steps']
step_size_schedule = config['step_size_schedule']
weight_decay = config['weight_decay']
data_path = config['data_path']
momentum = config['momentum']
batch_size = config['training_batch_size']

# Setting up the data and the model
raw_cifar = cifar10_input.CIFAR10Data(data_path)
global_step = tf.contrib.framework.get_or_create_global_step()

model = Model1(mode='train')
model1 = Model(mode='eval')

# Setting up the optimizer
boundaries = [int(sss[0]) for sss in step_size_schedule]
boundaries = boundaries[1:]
values = [sss[1] for sss in step_size_schedule]
learning_rate = tf.train.piecewise_constant(tf.cast(global_step, tf.int32),
                                            boundaries, values)
total_loss = model.mean_xent + weight_decay * model.weight_decay_loss

update_var_list = []
tvars = tf.global_variables()
for tvar in tvars:
    if "new" in tvar.name:
        update_var_list.append(tvar)
Example #5
0
 def __init__(self):
     self.model = Model()  # binding instances
     self.view = View(self)  # pass controller instance to view
Example #6
0
keep_prob = tf.placeholder(tf.float32)

X2 = tf.placeholder(tf.float32, shape=[None, 28 * 28])
Y2 = tf.placeholder(tf.float32, shape=[None, 10])
keep_prob2 = tf.placeholder(tf.float32)

X3 = tf.placeholder(tf.float32, shape=[None, 28 * 28])
Y3 = tf.placeholder(tf.float32, shape=[None, 10])
keep_prob3 = tf.placeholder(tf.float32)

Y4 = tf.placeholder(tf.float32, shape=[None, 10])
logitse1 = tf.placeholder(tf.float32, shape=[None, 10])
logitse2 = tf.placeholder(tf.float32, shape=[None, 10])

# Make model 1
model1 = Model1(X, Y, keep_prob)
logits1, predictions1 = model1.build()
loss_op1 = tf.reduce_mean(
    tf.nn.softmax_cross_entropy_with_logits(logits=logits1, labels=model1.Y))
train_op1 = tf.train.AdamOptimizer(
    learning_rate=model1.learning_rate).minimize(loss_op1)
accuracy1 = tf.reduce_mean(
    tf.cast(tf.equal(tf.argmax(predictions1, 1), tf.argmax(model1.Y, 1)),
            tf.float32))

# Make model 2
model2 = Model2(X2, Y2, keep_prob2)
logits2, predictions2 = model2.build()
loss_op2 = tf.reduce_mean(
    tf.nn.softmax_cross_entropy_with_logits(logits=logits2, labels=model2.Y2))
train_op2 = tf.train.AdamOptimizer(
Example #7
0
import numpy as np
from PIL import Image

from model1 import Model1

if __name__ == '__main__':
    img_path = ''
    img = Image.open(img_path).convert('L')
    img = np.array(img)

    model = Model1(10)

    y_ = model.forward(img)
    cls = np.argmax(y_)
Example #8
0
# Setting up training parameters
max_num_training_steps = config['max_num_training_steps']
num_output_steps = config['num_output_steps']
num_summary_steps = config['num_summary_steps']
num_checkpoint_steps = config['num_checkpoint_steps']
step_size_schedule = config['step_size_schedule']
weight_decay = config['weight_decay']
data_path = config['data_path']
momentum = config['momentum']
batch_size = config['training_batch_size']

# Setting up the data and the model
raw_cifar = cifar10_input.CIFAR10Data(data_path)
global_step = tf.contrib.framework.get_or_create_global_step()
model = Model(mode='train')
model1 = Model1(mode='eval')
# Setting up the optimizer
boundaries = [int(sss[0]) for sss in step_size_schedule]
boundaries = boundaries[1:]
values = [sss[1] for sss in step_size_schedule]
learning_rate = tf.train.piecewise_constant(tf.cast(global_step, tf.int32),
                                            boundaries, values)
total_loss = model.mean_xent + weight_decay * model.weight_decay_loss

update_var_list = []
tvars = tf.global_variables()
for tvar in tvars:
    if "new" in tvar.name:
        update_var_list.append(tvar)

old_list = []
Example #9
0
import os
import matplotlib.pyplot as plt

from model1 import Model1
from dataset import Dataset


if __name__ == '__main__':
    root = 'digit_data'
    train_root = os.path.join(root, 'train')
    val_root = os.path.join(root, 'val')

    num_epoch = 50
    learning_rate = .001

    model = Model1(10, learning_rate)

    train_dset = Dataset(train_root)
    val_dset = Dataset(val_root)
    train_dset.load_numpy_data(augment=True)
    val_dset.load_numpy_data(augment=True)

    train_images, train_labels = train_dset.images, train_dset.labels
    val_images, val_labels = val_dset.images, val_dset.labels

    assert len(train_images) == len(train_labels)
    assert len(val_images) == len(val_labels)

    len_train_data = len(train_images)
    len_val_data = len(val_images)
Example #10
0
        n_worst = nsmallest(n, y_range, key=lambda y: cm[y, y] if cm[y, y] != 0 else 1)
        cm = {(y1, y2): cm[y1, y2] for y1, y2 in cm if y1 in n_worst or y2 in n_worst}
    return cm


if __name__ == '__main__':
    total = time()

    # Model 1
    model1_path = Path('model/model1')
    model1 = None
    try:
        model1 = load_model(model1_path)
    except FileNotFoundError:
        train1 = preprocess(Path('data/train1.wtag'))
        model1 = Model1(lambda_=1, beam=3)
        model1.fit(*train1)
        model1.save_model(model1_path)
        train1_tags = list(chain(*train1[1]))
        print(f'Model 1 Train Accuracy: {accuracy(train1_tags, train1_tags)}')
    finally:
        test1 = preprocess(Path('data/test1.wtag'))
        test1_true_tags = list(chain(*test1[1]))
        test1_pred_tags = list(chain(*model1.predict(test1[0])))
        print(f'Model 1 Test Accuracy: {accuracy(test1_true_tags, test1_pred_tags)}')
        confusion = confusion_matrix(test1_true_tags, test1_pred_tags, model1.tag_vocabulary, n=10)
        tags = [tag for tag in model1.tag_vocabulary if (tag, tag) in confusion]
        tags.sort(key=lambda tag: confusion[tag, tag])
        print(f'Model 1 Test Confusion Matrix:')
        print(''.ljust(5) + ''.join(t.ljust(5) for t in tags))
        rows = [r.ljust(5) + ''.join([f'{confusion[r, c]:.2f}'.ljust(5) for c in tags]) for r in tags]