Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

5.May progress

isacg5 edited this page Jun 14, 2022 · 22 revisions

First week

  • Modify the configuration to instantly initialise Node-Red and the servers when the raspberry is on.

    • For Node-Red: Following these steps it works correctly.
      • Once Node-Red is started, is also necessary to launch the url in chromium to let the user see the user interface. I have done ir following these steps.
    • For the flask web servers: Modifying the folder init.d located in /etc/init.d adding a file to start or stop the web server and registering to be run at start-up and shutdown as explained here.
      • Problems:
        1. Found multiple errors from some libraries (ModuleNotFoundError: No module named 'x'). After some searchs, found the solution here. In the sys.path the was the route as root in the init.d script, but not the correct one. By adding it that error dissapeared.
        2. The next error was about numpy (RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd). The solution was found here, by upgrading numpy ignoring the current installation.
  • Flask server: Create a 2fa authentication for both servers on flask. Based on this example it works correctly.

    • Problem: When using Node-Red and displaying the url with the template, the code does not work. The error is 'CSRF do not match'.

Second week

  • Flask server: Try to solve the problem found the previous week.
    • Solution: After a deep study of the code, I have realised that there was a problem with the session generated on flask, that from one function to other was missed. The solution has been pass the session in the arguments of the return method in the functions needed, and add a function to get the dictionary of the function from the string, since the argument passed is recognised as string. Here is the video that shows the autostart of Node-Red when the raspberry is turned on and the registration and login of both cameras. IMAGE ALT TEXT
    • Add certificates to change http to https, more secure.

Third week

  • Docker: Install docker and learn how it works.
    • Creation of a container for the project. To do this divide the files in different parts to try them separated; the file to obtain the read of all the sensors, the flask servers and Node-Red.
      • Problems:
        • For the first case, after add all the requirements needed, errors in the spi function and w1-gpio module appeared, since the docker does not have that infomartion. IMAGE ALT TEXT

          To solve it is necessary to run the docker giving privileges, with --privileged command. IMAGE ALT TEXT

        • For the second case in the flask servers, did not appear anything when connecting to the URL. The solution is to add the port that is going to be used in the dockerfile with the EXPOSE XXXX, as well as running the docker with -p XXXX:XXXX.

        • To join both cases in Node-Red, and using the same image base as before, the docker does not work since docker does not have systemd and Node-Red needs it to start as a service. However, it has been found a project where is created a replacement for systemd in docker. After install it, Node-Red is launched but it does not finish to start. IMAGE ALT TEXT

          Instead, trying the Node-Red image that the official Node-Red provides, is not possible to execute any other command since apt-get do not work. After some searchs and tries, the reason why apt-get does not work is because the image is using apline. The solution for this has been to create a customized image. By cloning the repository and changing the parameters for a Rapsberry use in docker-custom/docker-debian.sh. Once the script is built, a base image is obtained. That is the image base that is user in the dockerfile. With this, the dockerfile works now with apt-get. But is not able to make work any of the two other cases, in the first case due to a docker permission on spi even though is executed with --privileged IMAGE ALT TEXT

          and the flask server due to is not possible install OpenCV. It keeps trying to install it but the error persists all the times. IMAGE ALT TEXT

Fourth week

  • Write chapters 2 and 3 of the project.
  • MQ-135: Understand how the ammonia sensor works. Based on this page to obtain the values according to the datasheet.
    • Explanation: The table in the datasheet is log. To convert it to linear, is necessary to obatin both limit points of the line. Since we want to measure NH3, the points are p1 = (10, 2.65) and p2 = (200, 0.79). By calculating with the two points form the slope (formula applied here), we get the slope = -0.42. Finally, by converting into log 10 the point of the left, we get the curve applied in the script NH3Curve = [1, 0.423, -0.42]. Here is a picture of how the sensor reacts when is put very close to a bottle of ammonia versus when is in the clean air.

IMAGE ALT TEXT IMAGE ALT TEXT

  • Search mice dataset:
    • Found one dataset of 16235 images of mice viewed from above and a xml file with the coordinated of an ellipse. To try if this dataset is valid to detec mice as wanted there have been a process:

      • Create a python file that converted the xml file into one adapted to the coordinates of a rectangle instead of an ellipse. This is how the values were in the initial dataset:

      IMAGE ALT TEXT

      This is how the bounding box looks like after execute the script created to convert the ellipse into rectangle:

      IMAGE ALT TEXT

      The change looks like this: IMAGE ALT TEXT

      • Separate the images into train a validation.

      • Load the dataset on google colab. This step has been a problem because google colab was not able to upload such a big dataset. To solve this, the things that have been tried:

        • Compress the dataset, did not work either.
        • Load it form google drive, did not work.
        • Use kaggle to upload the compress dataset and load this dataset from there. This is the solution that worked.
      • Train a model. Since the datasdet is that big, google colab was not able to finish to train the model and turned into disconected. Tried different solutions, such this, but no one worked.

        • Tried to compensate more the division of the dataset into 70% train 30% validate, since is theorically the best approach. It was still too big to finish before disconect.
        • Tried with 60% - 40%, but was not enough either.
        • The approach tried at this point was reduce the epochs from 80 to 25. The maximum epochs reached before it disconnected were 24 epochs.
        • Reduce to 20 epochs. After more than 3 hours, the execution with 20 epochs has finished.

        IMAGE ALT TEXT

        • Once the model is created, can be evaluated to see how it perfoms against new data.

        IMAGE ALT TEXT

        • Even though the percentage of performance agaings the new data is quite good (90%), the model does not work well when using the model in real time. Here are two examples that show that it recognises the mouse on the images trained as well as it detects noise, and how it does not detect another mouse in a picture that has not been trained. IMAGE ALT TEXT IMAGE ALT TEXT