Esempio n. 1
0
    def data_init(self):
        save_path = r"model_saver\AE_circle"
        out_dir_prefix = os.path.join(save_path, "model")
        height = 64
        width = 64
        epochs = 50
        GPU_ratio = 0.5
        batch_size = 12
        train_ratio = 0.7

        pic_path = r'./good samples'
        (self.x_train, self.x_train_label, no1, no2) = cm.data_load(pic_path, train_ratio=1, resize=(width, height), \
                                                          has_dir=False)
        print(self.x_train.shape)
        # self.ui.plainTextEdit.appendPlainText('x_train.shape = {}'.format(x_train.shape))
        print('x_train.shape = {}'.format(self.x_train.shape))
        # self.ui.label.setText('x_train.shape = {}'.format(x_train.shape))

        # prepare test data
        pic_path = r'./xxx'
        (self.x_train_2, self.x_train_label_2, self.x_test_2, self.x_test_label_2) = cm.data_load(pic_path, train_ratio,
                                                                              resize=(width, height), shuffle=True,
                                                                              normalize=True)

        print('x_test shape = ', self.x_test_2.shape)
        # self.ui.plainTextEdit.appendPlainText('x_test shape = {}'.format(x_test_2.shape))
        print('x_test shape = {}'.format(self.x_test_2.shape))

        print('x_test_label shape = ', self.x_test_label_2.shape)
        # self.ui.plainTextEdit.appendPlainText('xx_test_label shape = {}'.format(x_test_label_2.shape))
        print('x_test_label shape = {}'.format(self.x_test_label_2.shape))
Esempio n. 2
0
 def data_init(self):
     pic_path = r'D:\dataset\xxx'
     (x_train, x_train_label, no1, no2) = cm.data_load(pic_path,
                                                       train_ratio=1,
                                                       resize=(width,
                                                               height),
                                                       has_dir=True)
     print(x_train.shape)
     print(x_train_label)
Esempio n. 3
0
    def run(self):
        try:
            print("Start train data pre-process\n")
            (x_train, y_train_label, no1, no2) = cm.data_load(self.train_dir_name, train_ratio=self.train_ratio,
                                                              resize=(self.resize_width,self.resize_height),
                                                              has_dir=self.train_has_dir)
            print('Training data shape = {}'.format(x_train.shape))

            print("Start test data pre-process\n")
            (x_train_2, y_train_label_2, x_test, y_test_label) = cm.data_load(self.test_dir_name, train_ratio=0,
                                                              resize=(self.resize_width, self.resize_height),
                                                              has_dir=self.test_has_dir)
            print('Test data shape = {}'.format(x_test.shape))
            print('Test label shape = {}'.format(y_test_label.shape))
        except:
            print("在進行訓練資料前處理時發生錯誤")

        self.ae = AI.AE(input_dim=[None, self.resize_width, self.resize_height, 3])
        self.ae.train(x_train,x_test,y_test_label,self.GPU_ratio,self.epoch,
                      self.batch_size,self.fine_tune,self.save_ckpt)

        self.finish_flag.emit()
Esempio n. 4
0
                # 'model_saver/'為置放的資料夾,'combined_model.pb'為檔名
                # with tf.gfile.GFile("model_saver/pb_CLASF_circle__model.pb", "wb") as f:
                #     f.write(output_graph_def.SerializeToString())
                #     print("PB file saved successfully")


if __name__ == "__main__":
    save_path = r"model_saver\binary_CLASF_circle"
    out_dir_prefix = os.path.join(save_path, "model")
    height = 64
    width = 64
    epochs = 20
    GPU_ratio = 0.8
    batch_size = 8
    train_ratio = 0.7
    # prepare training data
    pic_path = r'D:\dataset\Halcon_circle'
    classifier_num = 2
    (x_train, x_train_label, x_test, x_test_label) = cm.data_load(pic_path, train_ratio=train_ratio, resize=(width, height), has_dir=True)
    print("x_train shape = ",x_train.shape)
    print("x_test shape = ", x_test.shape)
    x_train_label = np_utils.to_categorical(x_train_label, classifier_num)
    x_test_label = np_utils.to_categorical(x_test_label, classifier_num)
    print("train label shape = ",x_train_label.shape)
    print("test label shape = ", x_test_label.shape)

    CLASF = Classification(classifier_num,input_dim = [None,width,height,3], save_path=save_path)
    CLASF.train(x_train, x_train_label, x_test, x_test_label, GPU_ratio=GPU_ratio, epochs=epochs,
                batch_size=batch_size, fine_tune=True)
Esempio n. 5
0
            return train_ave_loss, test_ave_loss, acc


if __name__ == "__main__":

    #prepare training data
    # pic_path = r'E:\dataset\forAE\pill\train\Good'
    pic_path = r'E:\dataset\forAE\circle\train\Good'
    #pic_path = r"G:/我的雲端硬碟/Python/Code/Pycharm/P_UI_Test/goodsamples"
    # pic_path = r"G://我的雲端硬碟//Python//Code//Pycharm//P_UI_Test//goodsamples"
    #pic_path = "G:\\我的雲端硬碟\\Python\\Code\\Pycharm\\P_UI_Test\\goodsamples"
    # pic_path = 'C:\Users\highh\OneDrive\Desktop\goodsamples'
    #pic_path = "E:/dataset/Surface_detection/0"
    (x_train, x_train_label, no1, no2) = cm.data_load(pic_path,
                                                      train_ratio=1,
                                                      resize=(width, height),
                                                      has_dir=False)
    print(x_train.shape)
    #print("這是打包exe中文的輸出測試")
    # print(x_train_label)

    #prepare test data
    #pic_path = r'E:\dataset\forAE\pill\test'
    pic_path = r'E:\dataset\forAE\circle\test'
    (no_care, no_care_2, x_test, x_test_label) = cm.data_load(pic_path,
                                                              train_ratio=0,
                                                              resize=(width,
                                                                      height),
                                                              shuffle=True,
                                                              normalize=True)
    # print('x_train shape = ',x_train_2.shape)
Esempio n. 6
0
ref:
https://zhuanlan.zhihu.com/p/32887066
'''

import tensorflow as tf
from tensorflow.python.platform import gfile
import common as cm
from keras.utils import np_utils

model_filename = "model_saver/pb_CLASF_circle__model.pb"

#data preprocess
pic_path = r'.\circle_test'
classifier_num = 2
(x_train, x_train_label, x_test, x_test_label) = cm.data_load(pic_path,
                                                              train_ratio=0,
                                                              resize=(64, 64),
                                                              has_dir=False)
print(x_test_label.shape)
x_test_label = np_utils.to_categorical(x_test_label, classifier_num)
print("test label shape = ", x_test_label.shape)

with tf.Session() as sess:
    with gfile.FastGFile(model_filename, 'rb') as f:

        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
        sess.graph.as_default()

        tf.import_graph_def(graph_def, name='')  #導入計算圖

    sess.run(tf.global_variables_initializer())  #將變數初始化