Beispiel #1
0
    CYAN = '\033[96m'
    BLUE = '\033[94m'
    GREEN = '\033[92m'
    YELLOW = '\033[93m'
    RED = '\033[91m'
    END = '\033[0m'


while True:
    try:
        cin = input('image path: ')
        imagePath = Path(cin)

        img = Image.open(imagePath)
        img.load()
        img = resize_image(img, 100, 125)
        data = np.asarray(img, dtype="float32")
        data /= 255
        data = np.reshape(data, (1, 125, 100, 4))
        result = model.predict(data)
        print(color.BLUE + 'Result:' + color.END)
        if result[0][0] > .5:
            if result[0][0] > .9:
                print(color.GREEN + 'Male   (' + str(result[0][0]) + ')' +
                      color.END)
                print(color.RED + 'Female (' + str(result[0][1]) + ')' +
                      color.END)
            else:
                print(color.CYAN + 'Male   (' + str(result[0][0]) + ')' +
                      color.END)
                print(color.BLUE + 'Female (' + str(result[0][1]) + ')' +
Beispiel #2
0
                     loss='categorical_crossentropy',
                     learning_rate=0.001)

#training
model = tflearn.DNN(network, tensorboard_verbose=3)
model.fit(X,
          Y,
          n_epoch=13,
          shuffle=True,
          validation_set=0.2,
          show_metric=True,
          batch_size=96,
          run_id='brandberg')

#classifier
while True:
    try:
        cin = input('image path: ')
        imagePath = Path(cin)

        img = Image.open(imagePath)
        img.load()
        img = resize_image(img, 160, 180)
        data = np.asarray(img, dtype="float32")
        data /= 255
        data = np.reshape(data, (1, 180, 160, 4))
        result = model.predict(data)
        print('Male   (' + str(result[0][0]) + ')')
        print('Female (' + str(result[0][1]) + ')')
    except FileNotFoundError:
        print('File not found.')
    csv_dir = "/home/goerlab/Bilinear-CNN-TensorFlow/core/model/20180110/record/"
    csvfile = open(csv_dir + "test_detail.csv", "wb")
    writer = csv.writer(csvfile)
    writer.writerow(["labels", "prediction", "confidence_score", "file_name"])
    image_dir = "/media/goerlab/My Passport/Welder_detection/dataset/20180109/Data/val/"
    cnt = 0
    for dirc in os.listdir(image_dir):
        subdir = image_dir + dirc + '/'
        if not os.path.isfile(subdir):
            for subdirc in os.listdir(subdir):

                file_name = subdir + subdirc
                print(file_name)
                file_image = data_utils.load_image(file_name)
                file_image = data_utils.resize_image(file_image, 448, 448)
                #file_image=cv2.imread(file_name)
                #file_image=cv2.resize(file_image,(448,448))

                #file_image=file_image*(1./255)-0.5
                trans_image = np.asarray(file_image).reshape((1, 448, 448, 3))
                #trans_image=trans_image(1./255)-0.5

                real_predict, real_fc3l, real_confidence_score = sess.run(
                    [prediction, vgg.fc3l, confidence_score],
                    feed_dict={imgs: trans_image})
                #writer.writerow([str(dirc),real_predict[0],real_proba[0],file_name])
                # print(trans_image)
                real_label = int(dirc)
                print("label:%d, prediction:%d, confidence score:%f" %
                      (real_label, real_predict, real_confidence_score))
Beispiel #4
0
    cnt=0
    print("here")
    for root,dirs,files in os.walk(image_dir):
        print(root)
        for i in files:
            print("file:%s" % (i))
            filename=os.path.splitext(i)
            if filename[1]=='.bmp':
                image_file=root+"/"+i

            real_label=0
            #file_name=image_dir+dirc
            print(image_file)
            file_image=data_utils.load_image(image_file)
            croped=crop_image(file_image)
            file_image=data_utils.resize_image(croped,448,448)
            #file_image=cv2.imread(file_name)
            #file_image=cv2.resize(file_image,(448,448))



            #file_image=file_image*(1./255)-0.5
            trans_image=np.asarray(file_image).reshape((1,448,448,3))
            #trans_image=trans_image(1./255)-0.5

            real_predict,real_fc3l,real_confidence_score,top1_out,top2_out=sess.run([prediction,vgg.fc3l,confidence_score,top1,top2],feed_dict={imgs:trans_image})
            #writer.writfor i in files:
            print("file:%s" % (i))
            filename=os.path.splitext(i)
            if filename[1]=='.bmp':
                image_file=root+"/"+i