简体   繁体   English

TensorFlow 二进制分类

[英]TensorFlow Binary Classification

I'm trying to make a simple binary image classification with TensorFlow, but the results are just all over the place.我正在尝试使用 TensorFlow 进行简单的二进制图像分类,但结果到处都是。

The classifier is supposed to check whether my gate is open or closed.分类器应该检查我的门是打开还是关闭。 I already have some python scripts to rotate and crop the images to eliminate the surroundings, with an image size of 130w*705h.我已经有一些 python 脚本来旋转和裁剪图像以消除周围环境,图像大小为 130w*705h。

Images are below.图片如下。 I know I must be doing something totally wrong, because the images are almost night and day of a difference, yet it still gives completely random results.我知道我一定做错了什么,因为图像几乎是白天和黑夜的差异,但它仍然给出完全随机的结果。 Any tips?有小费吗? Is there a simpler library or maybe a cloud service I could use for this if TF is too complicated?如果 TF 太复杂,是否有一个更简单的库或者我可以使用的云服务?

Any help is appreciated, thanks!任何帮助表示赞赏,谢谢!

Gate Closed大门已关闭在此处输入图像描述

Gate Open门打开在此处输入图像描述

Just compute the average grey value of your images and define a threshold.只需计算图像的平均灰度值并定义阈值。 If you want something more sophisticated compute average gradients or something like that.如果你想要更复杂的计算平均梯度或类似的东西。 Your problem seems far too simple to use TF or CV.您的问题似乎太简单了,无法使用 TF 或 CV。

After taking into consideration Martin's Answer , I decided to go with average grays after some filtering and edge detection.考虑到Martin 的回答后,我决定 go 经过一些过滤和边缘检测后具有平均灰度。

I think it will work great for my case, thanks!我认为这对我的情况很有用,谢谢!

Some code:一些代码:

import cv2
import os
import numpy as np

# https://medium.com/sicara/opencv-edge-detection-tutorial-7c3303f10788

inputPath = '/Users/axelsariel/Desktop/GateImages/Cropped/'

# subDir = 'Closed/'
subDir = 'Open/'

openImagesList = os.listdir(inputPath + subDir)
for image in openImagesList:
    if not image.endswith('.JPG'):
        openImagesList.remove(image)

index = 0
while True:
    image = openImagesList[index]

    img = cv2.imread(inputPath + subDir + image)

    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    gray = cv2.medianBlur(gray,11)
    grayFiltered = cv2.bilateralFilter(gray, 7, 50, 50)

    edgesFiltered = cv2.Canny(grayFiltered, 80, 160)

    images = np.hstack((gray, grayFiltered, edgesFiltered))
    cv2.imshow(image, images)


    key = cv2.waitKey()

    if key == 3:
        index += 1
    elif key == 2:
        index -= 1
    elif key == ord('q'):
        break
    cv2.destroyAllWindows()

Average Grays after filtering:过滤后的平均灰度: 过滤后的平均灰度

Filtering steps:过滤步骤: 过滤器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM