This repository is my mini-thesis with my partner @iqbal757, where he uses ANN to detect fire. Also, fully supported by master of Python @vajrayudhar. This tutorial will tell you how to use TensorFlow to detect a fire on Windows 10. I haven't tried yet on Windows 8, 7 and Linux. I'm using TensorFlow-GPU version 1.9.0
This readme describes every step required to get going with fire detection:
- Installing Anaconda CUDA, and cuDNN
- Setting up the directory
- Download pictures / dataset
- Preparing Telegram Bot
- Setting Up TensorFlow and Preparing Necessary Packages
- Training
- Testing
Next time, I will make this tutorial on YouTube
I follow this YouTube video tutorial by Mark Jay, which shows the process for installing CUDA, and cuDNN. You do not need to install TensorFlow as shown in the video, because we will do that later. I suggest that you choose CUDA v9.0.176 and cuDNN v7.1, cause I'm using that version. After that download and install Anaconda. Also, my python version is Python 3.6.5. This is my laptop specification
- Processor : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80 GHz (8 CPUs)
- RAM : 8192 MB
- OS : Windows 10 Enterprise 64-bit
- GPU : NVIDIA GeForce GTX 1050
Version
- TensorFlow-GPU version 1.9.0
- Python 3.6.5
- CUDA v9.0.176
- cuDNN v7.1
- Anaconda 5.2.0
Notes : It depends on you to use what version, but I tried several times, and it didn't work. So this is the successful combination between the Tensorflow-GPU Version, CUDA Version, cuDNN Version, Anaconda Version, and Python Version.
This tutorial also requires several additional Python packages.
- Create a folder directly in C: and name it “tensorflow1”.
- Create a folder "dataset" inside tensorflow1 folder
- Download cam.py and train.py, and put it inside tensorflow1 folder
TensorFlow needs hundreds of images of an object to train. Here I have 9844 Fire pictures and 8000 Non-fire pictures. I capture this picture with my partner @iqbal757 for our Mini-thesis. Download the dataset and put it inside dataset folder
The purpose of making this telegram bot is to notify the user, that the webcam has detected a fire.
- Search for the “@BotFather” telegram bot (he’s the one that’ll assist you with creating and managing your bot)
- Click on or type /newbot to create a new bot.
- Follow instructions and make a new name for your bot. Although, its screen name can be whatever you like. I have chosen “test” as the screen name and “testfiredetection_bot” as its username.
- Congratulations! You have created your first bot. You should see a new API token generated for it (for example, in the picture, you can see my newly generated token is 944415410:AAFCIgbTCjs-_ZAEPz4YciCGzg5mX_FFF9M)
- Now you can search for your newly created bot on telegram
- For more details, see this tutorial in picture
After created Telegram Bot we need to know the chat id for sending notifications to the user. Follow this step to get the chat id
- Type anything on the bot and send it
- Open web browser and type
https://api.telegram.org/bot**YourBOTToken**/getUpdates
- In this case, my Bot Token is 944415410:AAFCIgbTCjs-_ZAEPz4YciCGzg5mX_FFF9M
- So type
https://api.telegram.org/bot944415410:AAFCIgbTCjs-_ZAEPz4YciCGzg5mX_FFF9M/getUpdates
- If the process didn't work, try again from step 1
- If you make it, you will see the id : your id (for example, in the picture, you can see my id : 389776309)
- For more details, see this tutorial in picture
Next we'll go to our directory C:\tensorflow1, and follow these instructions :
- Go to directory C:\tensorflow1
- Hold shift+right click mouse and click Open Powershell window here
- Type cmd and enter
- Create a new virtual environment called “tensorflow1” by issuing the following command:
C:\> conda create -n tensorflow1 pip python=3.6.5
- Install tensorflow-gpu in this environment by issuing:
C:\> pip install tensorflow-gpu==1.9.0
- Activate tensorflow by issuing:
C:\> activate tensorflow1
- Install the other necessary packages by issuing the following commands:
(tensorflow1) C:\> pip install python==3.6.5
(tensorflow1) C:\> pip install pillow==5.4.1
(tensorflow1) C:\> pip install lxml==4.3.2
(tensorflow1) C:\> pip install Cython==0.28.1
(tensorflow1) C:\> pip install numpy==1.16.3
(tensorflow1) C:\> pip install matplotlib==2.1.2
(tensorflow1) C:\> pip install pandas==0.24.2
(tensorflow1) C:\> pip install opencv-python==4.0.0.21
If everything has been set up correctly, TensorFlow will initialize the training.
- Go to directory C:\tensorflow1
- Hold shift+right click mouse and click Open Powershell window here
- Type cmd and enter
- Activate tensorflow by issuing:
C:\> activate tensorflow1
- Start training by issuing:
(tensorflow1) C:\> python train.py --image_dir="dataset" --how_many_training_steps=200
Notes : It depends on you, how many training steps (epoch) do you want, the default is 2000. I personally choose 200
When training begins, it will look like this:
The first part of the training, it will automatically download CNN Architecture Inception-v3. You can see the result of training on C:/tmp. Training will automatically stop.
Before you test, you should open cam.py
- Replace the video input at line 12. Adjust with your video input. If you use your Laptop Webcam, let it be 0.
- Replace line 57 with your API Token and your Chat ID
If you finish, you can start test to this Fire Detection.
- Go to directory C:\tensorflow1
- Hold shift+right click mouse and click Open Powershell window here
- Type cmd and enter
- Activate tensorflow by issuing:
C:\> activate tensorflow1
- Start testing by issuing:
(tensorflow1) C:\> python cam.py
- If you want to stop, press Ctrl+C
If everything is working properly, it will look like this.
If the percentage above 80%, it will automatically sending notifications to Telegram Bot, like this
You can change the percentage, by replacing cam.py at line 56.
Hope you make it till the end. Cheers.