def __init__(self) -> None: size = img_size self.conv1 = convolution.Convolution(input_shape=(size, size, ci), out_channel=oc1, kernel_size=(ks1, ks1), stride=(stride1, stride1), learning_rate=conv1_learning_rate, activate_func='relu') assert (size - ks1) % stride1 == 0 size = (size - ks1) // stride1 + 1 self.pool1 = pooling.Pooling(input_shape=(size, size, oc1), pool_size=ps1) assert size % 2 == 0 size //= 2 self.conv2 = convolution.Convolution(input_shape=(size, size, oc1), out_channel=oc2, kernel_size=(ks2, ks2), stride=(stride2, stride2), learning_rate=conv2_learning_rate, activate_func='relu') assert (size - ks2) % stride2 == 0 size = (size - ks2) // stride2 + 1 self.pool2 = pooling.Pooling(input_shape=(size, size, oc2), pool_size=ps2) assert size % 2 == 0 size //= 2 self.conv3 = convolution.Convolution(input_shape=(size, size, oc2), out_channel=oc3, kernel_size=(ks3, ks3), stride=(stride3, stride3), learning_rate=conv3_learning_rate, activate_func='relu') assert (size - ks3) % stride3 == 0 size = (size - ks3) // stride3 + 1 self.pool3 = pooling.Pooling(input_shape=(size, size, oc3), pool_size=ps3) assert size % 2 == 0 size //= 2 self.conv4 = convolution.Convolution(input_shape=(size, size, oc3), out_channel=oc4, kernel_size=(ks4, ks4), stride=(stride4, stride4), learning_rate=conv4_learning_rate, activate_func='relu') assert (size - ks4) % stride4 == 0 size4 = (size - ks4) // stride4 + 1 self.fc1 = full_connection.FullConnection( dim_in=size * size * oc3, dim_out=deepid_dim // 2, learning_rate=fc1_learning_rate, activate_func='relu') self.fc2 = full_connection.FullConnection( dim_in=size4 * size4 * oc4, dim_out=deepid_dim // 2, learning_rate=fc2_learning_rate, activate_func='relu')
for i in range(0, len(test_lables)): seq_id = processing.seq2id(test_sentences[i], word2id) target_id = test_lables[i] test_x.append(seq_id) test_y.append(int(target_id)) dev_x_tensor = data_loader.pad(dev_x, word2id, "-pad-") dev_y_tensor = torch.from_numpy(np.array(dev_y)) test_x_tensor = data_loader.pad(test_x, word2id, "-pad-") test_y_tensor = torch.from_numpy(np.array(test_y)) # print(test_x_tensor) plot_dev = [] plot_test = [] x = [] model = pooling.Pooling(len(word2id), 100, 2) with torch.no_grad(): for i in range(100): # model = pooling.Pooling(len(word2id), 100, 2) model.eval() model.load_state_dict(torch.load(model_url + "/" + str(i + 1) + ".pt")) correct = 0 total = 0 outputs1 = model(dev_x_tensor.long()) dev_right_num = train.accuracy_num(outputs1, dev_y_tensor) dev_acc = float(dev_right_num) / len(dev_y_tensor) * 100 outputs2 = model(test_x_tensor.long()) test_right_num = train.accuracy_num(outputs2, test_y_tensor) test_acc = float(test_right_num) / len(test_y_tensor) * 100 plot_dev.append(dev_acc)
def __init__(self) -> None: self.conv1 = convolution.Convolution((130, 130, 3), out_channel=96, kernel_size=(5, 5), stride=(1, 1), learning_rate=learning_rate, padding=(1, 1), activate_func='mfm') self.conv2a = convolution.Convolution((64, 64, 48), out_channel=96, kernel_size=(1, 1), stride=(1, 1), learning_rate=learning_rate, activate_func='mfm') self.conv2 = convolution.Convolution((64, 64, 48), out_channel=192, kernel_size=(3, 3), stride=(1, 1), learning_rate=learning_rate, padding=(1, 1), activate_func='mfm') self.conv3a = convolution.Convolution((32, 32, 96), out_channel=192, kernel_size=(1, 1), stride=(1, 1), learning_rate=learning_rate, activate_func='mfm') self.conv3 = convolution.Convolution((32, 32, 96), out_channel=384, kernel_size=(3, 3), stride=(1, 1), learning_rate=learning_rate, padding=(1, 1), activate_func='mfm') self.conv4a = convolution.Convolution((16, 16, 192), out_channel=384, kernel_size=(1, 1), stride=(1, 1), learning_rate=learning_rate, activate_func='mfm') self.conv4 = convolution.Convolution((16, 16, 192), out_channel=256, kernel_size=(3, 3), stride=(1, 1), learning_rate=learning_rate, padding=(1, 1), activate_func='mfm') self.conv5a = convolution.Convolution((16, 16, 128), out_channel=256, kernel_size=(1, 1), stride=(1, 1), learning_rate=learning_rate, activate_func='mfm') self.conv5 = convolution.Convolution((16, 16, 128), out_channel=256, kernel_size=(3, 3), stride=(1, 1), learning_rate=learning_rate, padding=(1, 1), activate_func='mfm') self.pool1 = pooling.Pooling((128, 128, 48), pool_size=2) self.pool2 = pooling.Pooling((64, 64, 96), pool_size=2) self.pool3 = pooling.Pooling((32, 32, 192), pool_size=2) self.pool4 = pooling.Pooling((16, 16, 128), pool_size=2) self.fc1 = full_connection.FullConnection(8 * 8 * 128, 512, learning_rate=learning_rate, activate_func='mfm') self.fc_out = full_connection.FullConnection( 256, class_num, learning_rate=learning_rate)