Exemplo n.º 1
0
 def __init__(self, data_class):
     sign_handle = import_data.DealSign()
     self.data_class = data_class
     trainData, self.trainFlag, testData, self.testFlag = sign_handle.readFile(
         self.data_class)
     self.image_size = 15
     self.channal = 16
     self.num_classes = 5
     self.batch_size = 16 if self.data_class == "person" else 32
     self.lambda_val = 0.5
     self.m_plus = 0.9
     self.m_minus = 0.1
     self.epsilon = 1e-9
     self.iter_routing = 3
     self.num_outputs_decode = 5
     self.num_dims_decode = 16
     self.trainData = self.two_dimension_graph(trainData)
     self.testData = self.two_dimension_graph(testData)
     self.capsnet_model = Capsnet(self.image_size, self.channal,
                                  self.num_classes, self.lambda_val,
                                  self.m_plus, self.m_minus, self.epsilon,
                                  self.iter_routing,
                                  self.num_outputs_decode,
                                  self.num_dims_decode, self.batch_size)
     self.sess = tf.Session(config=tf.ConfigProto(
         allow_soft_placement=True, log_device_placement=False))
     self.sess.run(tf.global_variables_initializer())
Exemplo n.º 2
0
 def __init__(self,data_class):
     sign_handle = import_data.DealSign()
     self.data_class = data_class
     self.trainData,self.trainFlag,self.testData,self.testFlag = sign_handle.readFile(self.data_class)
     self.image_size = 14
     self.channal = 16
     self.num_classes = 5
     self.max_gradient_norm = 10
     self.learning_rate = 5e-4
     self.batch_size = 16 if self.data_class == "person" else 32
     self.cnn = CnnModel(self.image_size,self.channal, self.num_classes, self.learning_rate,self.max_gradient_norm)
     self.sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=False))
     self.sess.run(tf.global_variables_initializer())
Exemplo n.º 3
0
            action_num[i] = np.sum(predict_action[i * action_batch:(i + 1) *
                                                  action_batch])
        print(action_num)
        action_acc = action_num / action_batch
        print(action_acc)
        accuracy = np.sum(action_num) / self.testFlag.shape[0]
        return accuracy

        # variousTag = np.unique(self.trainFlag)
        # rowacc = variousTag.shape[0]   # rowacc表示动作数目
        # accNumb = np.zeros((1, rowacc))
        # for i in range(self.testData.shape[0]):  # 判断测试集的分类
        #     k = np.matrix(self.testData[i, :])
        #     y = clf.predict(k)
        #     if y == self.testFlag[i]:
        #         accNumb[0, y-1] += 1
        # accNumb = accNumb / self.testData.shape[0]*rowacc
        # avg = np.sum(accNumb) / rowacc
        # std = np.sqrt(np.sum((accNumb - avg) ** 2)/rowacc)
        # print(avg,std)


if __name__ == "__main__":
    data_class = "person"
    # data_class = "people"
    sign_handle = import_data.DealSign()
    trainData, trainFlag, testData, testFlag = sign_handle.readFile(data_class)
    print('train and predict')
    svm_model = svmclassify(trainData, trainFlag, testData, testFlag)
    accuracy = svm_model.classify()
    print(accuracy)