diff --git a/Homework 3/.gitkeep b/Homework 3/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/Homework 3/Question 1 Proof/.gitkeep b/Homework 3/Question 1 Proof/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/Homework 3/Question 1 Proof/DAQ_initial.ino b/Homework 3/Question 1 Proof/DAQ_initial.ino deleted file mode 100644 index d7b5fb20434310676036e7a37f11012ad0122baa..0000000000000000000000000000000000000000 --- a/Homework 3/Question 1 Proof/DAQ_initial.ino +++ /dev/null @@ -1,1012 +0,0 @@ -/* -Group 1: Jeremy, Pavan, Ayush, Sam -Homework 3: DAQ -9th of Feburary, 2023 - -File Name: DAQ initial - -Goal/Purpose: To have a program that is able to collect and use all of the sensors and devices intended -for our project. In this code, it will read the GPS and RTC for time, then read the BME for temperature -and write it and the name of a picture taken to an SD Card), all while the LCD is displaying updates on -what task is currently being underwent and how many pictures/iterations of the loop have successfully executed. - -We spent around 12 hours total on this project, and referenced previous homeworks, online adafruit/arduino fourms, -and the provided test code on the 371 website. The data graph/mean/standard deviation is found in the excel file. -*/ -#include <Wire.h> -#include <SPI.h> -#include <Adafruit_Sensor.h> -#include "Adafruit_BME680.h" -#include <LiquidCrystal.h> -#include <TimeLib.h> -#include <DS1307RTC.h> -#include <Keypad.h> -#include "SdFat.h" -#include <Adafruit_VC0706.h> -//#include <SD.h> -#include <Adafruit_GPS.h> -#include "RTClib.h" -RTC_DS3231 rtc; -//GPS -#define GPSSerial Serial1 -#define GPSECHO1 false -#define GPSECHO2 false -#define GPSECHO3 false -#define PMTK_SET_NMEA_UPDATE_10SEC "$PMTK220,10000*2F" -#define PMTK_SET_NMEA_UPDATE_5SEC "$PMTK220,5000*2F" -#define PMTK_SET_NMEA_UPDATE_1HZ "$PMTK220,1000*1F" -#define PMTK_SET_NMEA_UPDATE_2HZ "$PMTK220,500*2B" -#define PMTK_SET_NMEA_UPDATE_5HZ "$PMTK220,200*2C" - -//SNAPSHOT -#if defined(__AVR__) || defined(ESP8266) -#include <SoftwareSerial.h> -SoftwareSerial cameraconnection(69, 3); -#else -#define cameraconnection Serial1 - -#endif -#define chipSelect 53 - -//BME SD -#define BME_SCK 13 -#define BME_MISO 12 -#define BME_MOSI 11 -#define BME_CS 10 -#define SD_CS_PIN SS -#define SEALEVELPRESSURE_HPA (1013.25) -Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection); -#define GPSMINLENGTH 55 -#define GPSMAXLENGTH 120 -Adafruit_GPS GPS(&GPSSerial); -char* GPS_sentence; -String GPS_sentence_string; -const int GPRMC_hour_index1 = 8; -const int GPRMC_hour_index2 = GPRMC_hour_index1 + 2; - -const int GPRMC_minutes_index1 = GPRMC_hour_index2; -const int GPRMC_minutes_index2 = GPRMC_minutes_index1 + 2; - -const int GPRMC_seconds_index1 = GPRMC_minutes_index2; -const int GPRMC_seconds_index2 = GPRMC_seconds_index1 + 2; - -const int GPRMC_milliseconds_index1 = GPRMC_seconds_index2 + 1; // skip the decimal point -const int GPRMC_milliseconds_index2 = GPRMC_milliseconds_index1 + 3; - -const int GPRMC_AV_code_index1 = 19; -const int GPRMC_AV_code_index2 = GPRMC_AV_code_index1 + 1; - -const int GPRMC_latitude_1_index1 = 21; -const int GPRMC_latitude_1_index2 = GPRMC_latitude_1_index1 + 4; - -const int GPRMC_latitude_2_index1 = GPRMC_latitude_1_index2 + 1; // skip the decimal point -const int GPRMC_latitude_2_index2 = GPRMC_latitude_2_index1 + 4; - -const int GPRMC_latitude_NS_index1 = 31; -const int GPRMC_latitude_NS_index2 = GPRMC_latitude_NS_index1 + 1; - -const int GPRMC_longitude_1_index1 = 33; -const int GPRMC_longitude_1_index2 = GPRMC_longitude_1_index1 + 5; // 0 - 180 so we need an extra digit - -const int GPRMC_longitude_2_index1 = GPRMC_longitude_1_index2 + 1; // skip the decimal point -const int GPRMC_longitude_2_index2 = GPRMC_longitude_2_index1 + 4; - -const int GPRMC_longitude_EW_index1 = 44; -const int GPRMC_longitude_EW_index2 = GPRMC_longitude_EW_index1 + 1; - -// pointers into a GPGGA GPS data sentence: - -const int GPGGA_hour_index1 = 8; -const int GPGGA_hour_index2 = GPGGA_hour_index1 + 2; - -const int GPGGA_minutes_index1 = GPGGA_hour_index2; -const int GPGGA_minutes_index2 = GPGGA_minutes_index1 + 2; - -const int GPGGA_seconds_index1 = GPGGA_minutes_index2; -const int GPGGA_seconds_index2 = GPGGA_seconds_index1 + 2; - -const int GPGGA_milliseconds_index1 = GPGGA_seconds_index2 + 1; // skip the decimal point -const int GPGGA_milliseconds_index2 = GPGGA_milliseconds_index1 + 3; - -const int GPGGA_latitude_1_index1 = 19; -const int GPGGA_latitude_1_index2 = GPGGA_latitude_1_index1 + 4; - -const int GPGGA_latitude_2_index1 = GPGGA_latitude_1_index2 + 1; // skip the decimal point -const int GPGGA_latitude_2_index2 = GPGGA_latitude_2_index1 + 4; - -const int GPGGA_latitude_NS_index1 = 29; -const int GPGGA_latitude_NS_index2 = GPGGA_latitude_NS_index1 + 1; - -const int GPGGA_longitude_1_index1 = 31; -const int GPGGA_longitude_1_index2 = GPGGA_longitude_1_index1 + 5; // 0 - 180 so we need an extra digit - -const int GPGGA_longitude_2_index1 = GPGGA_longitude_1_index2 + 1; // skip the decimal point -const int GPGGA_longitude_2_index2 = GPGGA_longitude_2_index1 + 4; - -const int GPGGA_longitude_EW_index1 = 42; -const int GPGGA_longitude_EW_index2 = GPGGA_longitude_EW_index1 + 1; - -const int GPGGA_fix_quality_index1 = 44; -const int GPGGA_fix_quality_index2 = GPGGA_fix_quality_index1 + 1; - -const int GPGGA_satellites_index1 = 46; -const int GPGGA_satellites_index2 = GPGGA_satellites_index1 + 2; - -// keep track of how many times we've read a character from the GPS device. -long GPS_char_reads = 0; - -// bail out if we exceed the following number of attempts. when set to 1,000,000 this corresponds -// to about 6 seconds. we need to do this to keep an unresponsive GPS device from hanging the program. -const long GPS_char_reads_maximum = 1000000; - -// define some of the (self-explanatory) GPS data variables. Times/dates are UTC. -String GPS_hour_string; -String GPS_minutes_string; -String GPS_seconds_string; -String GPS_milliseconds_string; -int GPS_hour; -int GPS_minutes; -int GPS_seconds; -int GPS_milliseconds; - -// this one tells us about data validity: A is good, V is invalid. -String GPS_AV_code_string; - -// latitude data -String GPS_latitude_1_string; -String GPS_latitude_2_string; -String GPS_latitude_NS_string; -int GPS_latitude_1; -int GPS_latitude_2; - -// longitude data -String GPS_longitude_1_string; -String GPS_longitude_2_string; -String GPS_longitude_EW_string; -int GPS_longitude_1; -int GPS_longitude_2; - -// velocity information; speed is in knots! -String GPS_speed_knots_string; -String GPS_direction_string; -float GPS_speed_knots; -float GPS_direction; - -String GPS_date_string; - -String GPS_fix_quality_string; -String GPS_satellites_string; -int GPS_fix_quality; -int GPS_satellites; - -String GPS_altitude_string; -float GPS_altitude; -String GPS_command; -char daysOfTheWeek[7][4] = - {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; -int RTC_hour, RTC_minute, RTC_second; -int RTC_year, RTC_month, RTC_day_of_month; -bool already_set_RTC_from_GPS; - - -SdFat SD_thingy; -File myFiley; - -char filename[ ] = "data.csv"; - -const char *monthName[12] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" -}; -tmElements_t tm; -Adafruit_BME680 bme; // I2C -const byte ROWS = 4; -const byte COLS = 3; - -char keys[ROWS][COLS] = { -{'1','2','3'}, -{'4','5','6'}, -{'7','8','9'}, -{'*','0','#'} -}; -bool getTime(const char *str) -{ - int Hour, Min, Sec; - - if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false; - tm.Hour = Hour; - tm.Minute = Min; - tm.Second = Sec; - return true; -} - -bool getDate(const char *str) -{ - char Month[12]; - int Day, Year; - uint8_t monthIndex; - - if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false; - for (monthIndex = 0; monthIndex < 12; monthIndex++) { - if (strcmp(Month, monthName[monthIndex]) == 0) break; - } - if (monthIndex >= 12) return false; - tm.Day = Day; - tm.Month = monthIndex + 1; - tm.Year = CalendarYrToTm(Year); - return true; -} -byte Arduino_colPins[COLS] = {2, 3, 18}; -byte Arduino_rowPins[ROWS] = {31, 33, 35, 37}; -Keypad kpd = Keypad( makeKeymap(keys), Arduino_rowPins, Arduino_colPins, ROWS, COLS ); - -const int rs = 12, en = 11, data4 = 36, data5 = 34, data6 = 32, data7 = 30; -LiquidCrystal lcd(rs, en, data4, data5, data6, data7); - - -void setup() { - if (!bme.begin()) { - Serial.println("Could not find a valid BME680 sensor, check wiring!"); - while (1); - bme.setTemperatureOversampling(BME680_OS_8X); - bme.setHumidityOversampling(BME680_OS_2X); - bme.setPressureOversampling(BME680_OS_4X); - bme.setIIRFilterSize(BME680_FILTER_SIZE_3); - bme.setGasHeater(320, 150); // 320*C for 150 ms - - } - //HW 2 - bool parse=false; - bool config=false; - - // get the date and time the compiler was run - if (getDate(__DATE__) && getTime(__TIME__)) { - parse = true; - // and configure the RTC with this info - if (RTC.write(tm)) { - config = true; - } - } - Serial.begin(115200); - while (!Serial); - Serial.println(F("BME680 test")); - - if (!bme.begin()) { - Serial.println("Could not find a valid BME680 sensor, check wiring!"); - while (1); - } - - // Set up oversampling and filter initialization - bme.setTemperatureOversampling(BME680_OS_8X); - bme.setHumidityOversampling(BME680_OS_2X); - bme.setPressureOversampling(BME680_OS_4X); - bme.setIIRFilterSize(BME680_FILTER_SIZE_3); - bme.setGasHeater(320, 150); // 320*C for 150 ms - - lcd.begin(16, 2); - Serial.println("About to write to LCD."); - Serial.println("LCD lines are 16 characters long."); - while (!Serial) ; // wait for Arduino Serial Monitor - delay(200); - if (parse && config) { - Serial.print("DS1307 configured Time="); - Serial.print(__TIME__); - Serial.print(", Date="); - Serial.println(__DATE__); - } else if (parse) { - Serial.println("DS1307 Communication Error :-{"); - Serial.println("Please check your circuitry"); - } else { - Serial.print("Could not parse info from the compiler, Time=\""); - Serial.print(__TIME__); - Serial.print("\", Date=\""); - Serial.print(__DATE__); - Serial.println("\""); - } - //HW 2 DONE - - //camera begin - #if !defined(SOFTWARE_SPI) -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) - if(chipSelect != 53) pinMode(53, OUTPUT); // SS on Mega -#else - if(chipSelect != 10) pinMode(10, OUTPUT); // SS on Uno, etc. -#endif -#endif - - - Serial.println("VC0706 Camera snapshot test"); - - // see if the card is present and can be initialized: - if (!SD_thingy.begin(chipSelect)) { - Serial.println("Card failed, or not present"); - // don't do anything more: - return; - } - - // Try to locate the camera - if (cam.begin()) { - Serial.println("Camera Found:"); - } else { - Serial.println("No camera found?"); - return; - } - // Print out the camera version information (optional) - char *reply = cam.getVersion(); - if (reply == 0) { - Serial.print("Failed to get version"); - } else { - Serial.println("-----------------"); - Serial.print(reply); - Serial.println("-----------------"); - } - //CAMERA END - - //GPS BEGIN - GPS.begin(9600); - - // turn on RMC (recommended minimum) and GGA (fix data, including altitude) - GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); - GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ); -} -void updateTime() { - Serial.println("Setting the RTC Date"); - bool parse=false; - bool config=false; - if (getDate(__DATE__) && getTime(__TIME__)) { - parse = true; - if (RTC.write(tm)) { - config = true; - } - while (!Serial); - delay(200); - if (parse && config) { - Serial.print("DS1307 configured Time="); - Serial.print(__TIME__); - Serial.print(", Date="); - Serial.println(__DATE__); - } else if (parse) { - Serial.println("DS1307 Communication Error :-{"); - Serial.println("Please check your circuitry"); - } else { - Serial.print("Could not parse info from the compiler, Time=\""); - Serial.print(__TIME__); - Serial.print("\", Date=\""); - Serial.print(__DATE__); - Serial.println("\""); - } - } -} -void writeCSV(String picname, String speed_knots, String direction) { - Serial.println("opening the csv file"); - while (!Serial) { } - Serial.print("Initializing SD card reading software... "); - if (!SD_thingy.begin(SD_CS_PIN)) { - Serial.println("SD initialization failed!"); - delay(100); - exit(0); - } - /* - Serial.println("initialization done."); - if(SD_thingy.exists(filename)) { - SD_thingy.remove(filename); - delay(100); - } - */ - myFiley = SD_thingy.open(filename, FILE_WRITE); - if (myFiley) { - Serial.print("Writing to "); Serial.print(filename); Serial.println("..."); - } else { - Serial.print("error opening "); Serial.println(filename); - delay(100); - exit(0); - } - myFiley.print(__TIME__);myFiley.print(",");myFiley.print(__DATE__);myFiley.print(",");myFiley.print(picname);myFiley.print(",");myFiley.print(speed_knots);myFiley.print(",");myFiley.println(direction); - Serial.println("Finished writing to file. Now close it, open it, read it."); - lcd.setCursor(0,1); - lcd.print("Closing"); - myFiley.close(); -} -String picturename = "IMAGE00.JPG"; -void getphoto() { - cam.setImageSize(VC0706_640x480); // biggest - //cam.setImageSize(VC0706_320x240); // medium - //cam.setImageSize(VC0706_160x120); // small - - // You can read the size back from the camera (optional, but maybe useful?) - uint8_t imgsize = cam.getImageSize(); - Serial.print("Image size: "); - if (imgsize == VC0706_640x480) Serial.println("640x480"); - if (imgsize == VC0706_320x240) Serial.println("320x240"); - if (imgsize == VC0706_160x120) Serial.println("160x120"); - - Serial.println("Snap in 3 secs..."); - lcd.setCursor(0,1); - lcd.print("Taking pic"); - delay(3000); - - if (! cam.takePicture()) - Serial.println("Failed to snap!"); - else - Serial.println("Picture taken!"); - lcd.setCursor(0,1); - lcd.print("Pic taken!"); - - // Create an image with the name IMAGExx.JPG - char picname[13]; - strcpy(picname, "IMAGE00.JPG"); - for (int i = 0; i < 100; i++) { - picname[5] = '0' + i/10; - picname[6] = '0' + i%10; - picturename[5] = '0' + i/10; - picturename[6] = '0' + i%10; - - // create if does not exist, do not open existing, write, sync after write - if (! SD_thingy.exists(picname)) { - break; - } - } - - // Open the file for writing - File imgFile = SD_thingy.open(picname, FILE_WRITE); - - // Get the size of the image (frame) taken - uint32_t jpglen = cam.frameLength(); - Serial.print("Storing "); - lcd.setCursor(0,1); - lcd.print("Storing"); - Serial.print(jpglen, DEC); - Serial.print(" byte image."); - - int32_t time = millis(); - pinMode(8, OUTPUT); - // Read all the data up to # bytes! - byte wCount = 0; // For counting # of writes - while (jpglen > 0) { - // read 32 bytes at a time; - uint8_t *buffer; - uint8_t bytesToRead = min((uint32_t)32, jpglen); // change 32 to 64 for a speedup but may not work with all setups! - buffer = cam.readPicture(bytesToRead); - imgFile.write(buffer, bytesToRead); - if(++wCount >= 64) { // Every 2K, give a little feedback so it doesn't appear locked up - Serial.print('.'); - wCount = 0; - } - //Serial.print("Read "); Serial.print(bytesToRead, DEC); Serial.println(" bytes"); - jpglen -= bytesToRead; - } - imgFile.close(); - - time = millis() - time; - Serial.println("done!"); - lcd.setCursor(0,1); - lcd.print("Done!"); - Serial.print(time); Serial.println(" ms elapsed"); -} - -int count = 0; -void loop() { - updateTime(); -if (! bme.performReading()) { - Serial.println("Failed to perform reading :("); - return; - } - - - -GPS_query(); -Serial.println(GPS_minutes * 60 + GPS_seconds); -Serial.print("TIME: ");Serial.println(__TIME__); - - -lcd.setCursor(0,0); -lcd.print("Entries: ");lcd.print(count); -getphoto(); -Serial.println(picturename); -float BME_temp = bme.temperature; -Serial.println(BME_temp); -float GPS_second = GPS_minutes * 60 + GPS_seconds; -writeCSV(picturename,(String)GPS_second,(String)BME_temp); - delay(1000); - -Serial.println("pic taken"); -count++; -delay(1000); - -} -int GPS_query() -{ - - // return 0 if we found good GPS navigational data and -1 if not. - - // The GPS device has its own microprocessor and, once we have loaded its parameters, - // free-runs at a 1 Hz sampling rate. We do not trigger its registration of - // latitude and longitude, rather we just read from it the last data record - // it has stored. And we do it one character at a time! - - // I will keep reading from the GPS until I have a complete sentence carrying valid - // navigational data, with a maximum number of reads to prevent the program from hanging. Once - // the GPS reports its updates latitude/longitude information, we'll push this to the - // LCD display, then return to the main loop. - - // zero out (or set to defaults) values returned by the GPS device in case we can't - // get it to respond. - GPS_hour = GPS_minutes = GPS_seconds = GPS_milliseconds = 0; - - GPS_AV_code_string = "V"; - - GPS_latitude_1 = GPS_latitude_2 = 0; - GPS_latitude_NS_string = "x"; - - GPS_longitude_1 = GPS_longitude_2 = 0; - GPS_longitude_EW_string = "y"; - - GPS_speed_knots = 0.; - GPS_direction = 0.; - - GPS_date_string = "000000"; - - GPS_fix_quality = GPS_satellites = 0; - - GPS_altitude = 0.; - - // initialize the number-of-reads counter since we might find ourselves - // with an unparseable data record, or an unresponsive GPS, and want to keep trying. - // This will let me protect against the data logger's program hanging. - GPS_char_reads = 0; - - // set a flag saying we want to keep trying; we'll use this to keep looking for - // useful navigation when the GPS is working fine, but still looking for satellites. - bool keep_trying = true; - - // Stay inside the following loop until we've read a complete GPS sentence with - // good navigational data, or else the loop times out. With GPS_char_reads_maximum - // set to a million this'll take about 6 seconds to time out. - - while (true) { - - // if we get back to this point but the keep_trying flag is false, we'll want - // to declare failure and quit. - - if(!keep_trying) return -1; - - // this gets the last sentence read from GPS and clears a newline flag in the Adafruit - // library code. - GPS_sentence = GPS.lastNMEA(); - Serial.println("printing raw"); - - - while(GPS_char_reads <= GPS_char_reads_maximum) - { - - // try to read a single character from the GPS device. - char single_GPS_char = GPS.read(); - - // bump the number of times we've tried to read from the GPS. - GPS_char_reads++; - - // now ask if we've received a complete data sentence. If yes, break - // out of this loop. - - if(GPS.newNMEAreceived()) break; - - } - - - // if we hit the limit on the number of character reads we'e tried, print a message and bail out. - if (GPS_char_reads >= GPS_char_reads_maximum) - { -Serial.println(GPS_sentence); - keep_trying = false; - - Serial.println("GPS navigation data not yet available. Try again later."); - - - return -1; - - } - - // get the last complete sentence read from GP; this automatically clears a newline flag inside - // the Adafruit library code. - GPS_sentence = GPS.lastNMEA(); - - // convert GPS data sentence from a character array to a string. - GPS_sentence_string = String(GPS_sentence); - - // now do a cursory check that the sentence we've just read is OK. Check that there is only - // one $, as the first character in the sentence, and that there's an asterisk (which commes - // immediately before the checksum). - - // sentence starts with a $? - bool data_OK = GPS_sentence_string.charAt(0) == '$'; - - // sentence contains no other $? The indexOf call will return -1 if $ is not found. - data_OK = data_OK && (GPS_sentence_string.indexOf('$', 2) < 0); - - // now find that asterisk... - data_OK = data_OK && (GPS_sentence_string.indexOf('*', 0) > 0); - - if (GPSECHO1) - { - Serial.println("\n******************\njust received a complete sentence, so parse stuff. Sentence is"); - Serial.println(GPS_sentence_string); - } - - // now parse the GPS sentence. I am only interested in sentences that begin with - // $GPGGA ("GPS fix data") or $GPRMC ("recommended minimum specific GPS/Transit data"). - - if(GPSECHO1) - { - Serial.print("length of GPS_sentence_string just received..."); - Serial.println(GPS_sentence_string.length()); - } - - // now get substring holding the GPS command. Only proceed if it is $GPRMC or $GPGGA. - GPS_command = GPS_sentence_string.substring(0, 6); - - // also trim it to make sure we don't have hidden stuff or white space sneaking in. - GPS_command.trim(); - - if(GPSECHO1) - { - Serial.print("GPS command is "); Serial.println(GPS_command); - } - - // if data_OK is true then we have a good sentence. but we also need the sentence - // to hold navigational data we can use, otherwise we'll want to keep listening. - // we can only work with GPRMC and GPGGA sentences. - - bool command_OK = GPS_command.equals("$GPRMC") || GPS_command.equals("$GPGGA"); - - // if we have a sentence that, upon cursory inspection, is well formatted AND might - // hold navigational data, continue to parse the sentence. If the GPS device - // hasn't found any satellites yet, we'll want to go back to the top of the loop - // to keep trying, rather than declaring defeat and returning. - - ////////////////////////////////////////////////////////////////////// - /////////////////////////// GPRMC sentence /////////////////////////// - ////////////////////////////////////////////////////////////////////// - - if (data_OK && GPS_command.equals("$GPRMC")) - { - - if(GPSECHO2) - { - Serial.print("\nnew GPS sentence: "); Serial.println(GPS_sentence_string); - } - - // parse the time. these are global variables, already declared. - - GPS_hour_string = GPS_sentence_string.substring(GPRMC_hour_index1, GPRMC_hour_index2); - GPS_minutes_string = GPS_sentence_string.substring(GPRMC_minutes_index1, GPRMC_minutes_index2); - GPS_seconds_string = GPS_sentence_string.substring(GPRMC_seconds_index1, GPRMC_seconds_index2); - GPS_milliseconds_string = GPS_sentence_string.substring(GPRMC_milliseconds_index1, - GPRMC_milliseconds_index2); - GPS_AV_code_string = GPS_sentence_string.substring(GPRMC_AV_code_index1, GPRMC_AV_code_index2); - - GPS_hour = GPS_hour_string.toInt(); - GPS_minutes = GPS_minutes_string.toInt(); - GPS_seconds = GPS_seconds_string.toInt(); - GPS_milliseconds = GPS_milliseconds_string.toInt(); - - if(GPSECHO2) - { - Serial.print("Time (UTC) = "); Serial.print(GPS_hour); Serial.print(":"); - Serial.print(GPS_minutes); Serial.print(":"); - Serial.print(GPS_seconds); Serial.print("."); - Serial.println(GPS_milliseconds); - Serial.print("A/V code is "); Serial.println(GPS_AV_code_string); - } - - // now see if the data are valid: we'll expect an "A" as the AV code string. - // We also expect an asterisk two characters from the end. Also check that the sentence - // is at least as long as the minimum length expected. - - data_OK = GPS_AV_code_string == "A"; - - // now look for the asterisk after trimming any trailing whitespace in the GPS sentence. - // the asterisk preceeds the sentence's checksum information, which I won't bother to check. - int asterisk_should_be_here = GPS_sentence_string.length() - 4; - - data_OK = data_OK && (GPS_sentence_string.charAt(asterisk_should_be_here) == '*'); - - if(GPSECHO2) - { - Serial.print("expected asterisk position "); Serial.print(asterisk_should_be_here); - Serial.print(" at that position: "); Serial.println(GPS_sentence_string.charAt(asterisk_should_be_here)); - } - - // now check that the sentence is not too short. - data_OK = data_OK && (GPS_sentence_string.length() >= GPSMINLENGTH); - - if (!data_OK) - { - - keep_trying = true; - - if (GPSECHO1) - { - Serial.print("GPS sentence not good for navigation: "); Serial.println(GPS_sentence_string); - Serial.println("I will keep trying..."); - } - - - } - - // if data are not good, go back to the top of the loop by breaking out of this if block. - // we've already set keep_trying to be true. - - if (!data_OK) break; - - // so far so good, so keep going... - - // now parse latitude - - GPS_latitude_1_string = GPS_sentence_string.substring(GPRMC_latitude_1_index1, - GPRMC_latitude_1_index2); - GPS_latitude_2_string = GPS_sentence_string.substring(GPRMC_latitude_2_index1, - GPRMC_latitude_2_index2); - GPS_latitude_NS_string = GPS_sentence_string.substring(GPRMC_latitude_NS_index1, - GPRMC_latitude_NS_index2); - - GPS_latitude_1 = GPS_latitude_1_string.toInt(); - GPS_latitude_2 = GPS_latitude_2_string.toInt(); - - if(GPSECHO2) - { - Serial.print("Latitude x 100 = "); Serial.print(GPS_latitude_1); Serial.print("."); - Serial.print(GPS_latitude_2); Serial.println(GPS_latitude_NS_string); - } - - // now parse longitude - - GPS_longitude_1_string = GPS_sentence_string.substring(GPRMC_longitude_1_index1, - GPRMC_longitude_1_index2); - GPS_longitude_2_string = GPS_sentence_string.substring(GPRMC_longitude_2_index1, - GPRMC_longitude_2_index2); - GPS_longitude_EW_string = GPS_sentence_string.substring(GPRMC_longitude_EW_index1, - GPRMC_longitude_EW_index2); - - GPS_longitude_1 = GPS_longitude_1_string.toInt(); - GPS_longitude_2 = GPS_longitude_2_string.toInt(); - - if(GPSECHO2) - { - Serial.print("Longitude x 100 = "); Serial.print(GPS_longitude_1); Serial.print("."); - Serial.print(GPS_longitude_2); Serial.println(GPS_longitude_EW_string); - } - - // now parse speed and direction. we'll need to locate the 7th and 8th commas in the - // data sentence to do this. so use the indexOf function to find them. - // it returns -1 if string wasn't found. the number of digits is not uniquely defined - // so we need to find the fields based on the commas separating them from others. - - int comma_A_index = GPRMC_longitude_EW_index2; - int comma_B_index = GPS_sentence_string.indexOf(",", comma_A_index + 1); - int comma_C_index = GPS_sentence_string.indexOf(",", comma_B_index + 1); - - GPS_speed_knots_string = GPS_sentence_string.substring(comma_A_index + 1, comma_B_index); - GPS_direction_string = GPS_sentence_string.substring(comma_B_index + 1, comma_C_index); - - GPS_speed_knots = GPS_speed_knots_string.toFloat(); - GPS_direction = GPS_direction_string.toFloat(); - - if(GPSECHO2) - { - Serial.print("Speed (knots) = "); Serial.println(GPS_speed_knots); - Serial.print("Direction (degrees) = "); Serial.println(GPS_direction); - } - - // now get the (UTC) date, in format DDMMYY, e.g. 080618 for 8 June 2018. - GPS_date_string = GPS_sentence_string.substring(comma_C_index+ + 1, comma_C_index + 7); - - if(GPSECHO2) - { - Serial.print("date, in format ddmmyy = "); Serial.println(GPS_date_string); - } - - // Write message to LCD now. It will look like this (no satellite data in this record): - // Sats: 4006.9539N - // N/A 08815.4431W - - - // print a summary of the data and parsed results: - if(GPSECHO3) - { - Serial.print("GPS sentence: "); Serial.println(GPS_sentence_string); - - Serial.print("Time (UTC) = "); Serial.print(GPS_hour); Serial.print(":"); - Serial.print(GPS_minutes); Serial.print(":"); - Serial.print(GPS_seconds); Serial.print("."); - Serial.println(GPS_milliseconds); - - Serial.print("Latitude x 100 = "); Serial.print(GPS_latitude_1); Serial.print("."); - Serial.print(GPS_latitude_2); Serial.print(" "); Serial.print(GPS_latitude_NS_string); - - Serial.print(" Longitude x 100 = "); Serial.print(GPS_longitude_1); Serial.print("."); - Serial.print(GPS_longitude_2); Serial.print(" "); Serial.println(GPS_longitude_EW_string); - - Serial.print("Speed (knots) = "); Serial.print(GPS_speed_knots); - Serial.print(" Direction (degrees) = "); Serial.println(GPS_direction); - - Serial.println("There is no satellite or altitude information in a GPRMC data sentence."); - - } - - // all done with this sentence, so return. - return 0; - - } // end of "if (data_OK && GPS_command.equals("$GPRMC"))" block - - ////////////////////////////////////////////////////////////////////// - /////////////////////////// GPGGA sentence /////////////////////////// - ////////////////////////////////////////////////////////////////////// - - if (data_OK && GPS_command.equals("$GPGGA")) - { - - if(GPSECHO2) - { - Serial.print("\nnew GPS sentence: "); Serial.println(GPS_sentence_string); - } - - // parse the time - - GPS_hour_string = GPS_sentence_string.substring(GPGGA_hour_index1, GPGGA_hour_index2); - GPS_minutes_string = GPS_sentence_string.substring(GPGGA_minutes_index1, GPGGA_minutes_index2); - GPS_seconds_string = GPS_sentence_string.substring(GPGGA_seconds_index1, GPGGA_seconds_index2); - GPS_milliseconds_string = GPS_sentence_string.substring(GPGGA_milliseconds_index1, - GPGGA_milliseconds_index2); - - GPS_hour = GPS_hour_string.toInt(); - GPS_minutes = GPS_minutes_string.toInt(); - GPS_seconds = GPS_seconds_string.toInt(); - GPS_milliseconds = GPS_milliseconds_string.toInt(); - - if(GPSECHO2) - { - Serial.print("Time (UTC) = "); Serial.print(GPS_hour); Serial.print(":"); - Serial.print(GPS_minutes); Serial.print(":"); - Serial.print(GPS_seconds); Serial.print("."); - Serial.println(GPS_milliseconds); - } - - // now get the fix quality and number of satellites. - - GPS_fix_quality_string = GPS_sentence_string.substring(GPGGA_fix_quality_index1, - GPGGA_fix_quality_index2); - GPS_satellites_string = GPS_sentence_string.substring(GPGGA_satellites_index1, - GPGGA_satellites_index2); - - int GPS_fix_quality = GPS_fix_quality_string.toInt(); - int GPS_satellites = GPS_satellites_string.toInt(); - - if(GPSECHO2) - { - Serial.print("fix quality (1 for GPS, 2 for DGPS) = "); Serial.println(GPS_fix_quality); - Serial.print("number of satellites = "); Serial.println(GPS_satellites); - } - - // now see if the data are valid: we'll expect a fix, and at least three satellites. - - bool data_OK = (GPS_fix_quality > 0) && (GPS_satellites >= 3); - - // now look for the asterisk. - int asterisk_should_be_here = GPS_sentence_string.length() - 4; - - data_OK = data_OK && (GPS_sentence_string.charAt(asterisk_should_be_here) == '*'); - - // now check that the sentence is not too short. - data_OK = data_OK && (GPS_sentence_string.length() >= GPSMINLENGTH); - - if (!data_OK) - { - - keep_trying = true; - - if (GPSECHO1) - { - Serial.print("GPS sentence not good for navigation: "); Serial.println(GPS_sentence_string); - Serial.println("I will keep trying..."); - } - - } - - // if data are not good, go back to the top of the loop by breaking out of this if block. - - if (!data_OK) break; - - // so far so good, so keep going... - - // now parse latitude - - String GPS_latitude_1_string = GPS_sentence_string.substring(GPGGA_latitude_1_index1, - GPGGA_latitude_1_index2); - String GPS_latitude_2_string = GPS_sentence_string.substring(GPGGA_latitude_2_index1, - GPGGA_latitude_2_index2); - String GPS_latitude_NS_string = GPS_sentence_string.substring(GPGGA_latitude_NS_index1, - GPGGA_latitude_NS_index2); - - int GPS_latitude_1 = GPS_latitude_1_string.toInt(); - int GPS_latitude_2 = GPS_latitude_2_string.toInt(); - - if(GPSECHO2) - { - Serial.print("Latitude x 100 = "); Serial.print(GPS_latitude_1); Serial.print("."); - Serial.print(GPS_latitude_2); Serial.println(GPS_latitude_NS_string); - } - - // now parse longitude - - String GPS_longitude_1_string = GPS_sentence_string.substring(GPGGA_longitude_1_index1, - GPGGA_longitude_1_index2); - String GPS_longitude_2_string = GPS_sentence_string.substring(GPGGA_longitude_2_index1, - GPGGA_longitude_2_index2); - String GPS_longitude_EW_string = GPS_sentence_string.substring(GPGGA_longitude_EW_index1, - GPGGA_longitude_EW_index2); - - int GPS_longitude_1 = GPS_longitude_1_string.toInt(); - int GPS_longitude_2 = GPS_longitude_2_string.toInt(); - - if(GPSECHO2) - { - Serial.print("Longitude x 100 = "); Serial.print(GPS_longitude_1); Serial.print("."); - Serial.print(GPS_longitude_2); Serial.println(GPS_longitude_EW_string); - } - - // let's skip the "horizontal dilution" figure and go straight for the altitude now. - // this begins two fields to the right of the num,ber of satellites so find this - // by counting commas. use the indexOf function to find them. - int comma_A_index = GPS_sentence_string.indexOf(",", GPGGA_satellites_index2 + 1); - int comma_B_index = GPS_sentence_string.indexOf(",", comma_A_index + 1); - - String GPS_altitude_string = GPS_sentence_string.substring(comma_A_index + 1, comma_B_index); - - float GPS_altitude = GPS_altitude_string.toFloat(); - - if(GPSECHO2) - { - Serial.print("Altitude (meters) = "); Serial.println(GPS_altitude); - } - - // Write message to LCD now. It will look like this: - // Sats: 4006.9539N - // 10 08815.4431W - - - // print a summary of the data and parsed results: - if(GPSECHO3) - { - Serial.print("GPS sentence: "); Serial.println(GPS_sentence_string); - - Serial.print("Time (UTC) = "); Serial.print(GPS_hour); Serial.print(":"); - Serial.print(GPS_minutes); Serial.print(":"); - Serial.print(GPS_seconds); Serial.print("."); - Serial.println(GPS_milliseconds); - - Serial.print("Latitude x 100 = "); Serial.print(GPS_latitude_1); Serial.print("."); - Serial.print(GPS_latitude_2); Serial.print(" "); Serial.print(GPS_latitude_NS_string); - - Serial.print(" Longitude x 100 = "); Serial.print(GPS_longitude_1); Serial.print("."); - Serial.print(GPS_longitude_2); Serial.print(" "); Serial.println(GPS_longitude_EW_string); - - Serial.print("Speed (knots) = "); Serial.print(GPS_speed_knots); - Serial.print(" Direction (degrees) = "); Serial.println(GPS_direction); - - Serial.print("Number of satellites: "); Serial.print(GPS_satellites); - Serial.print(" Altitude (meters): "); Serial.println(GPS_altitude); - - } - - // all done with this sentence, so return. - return 0; - - } // end of "if (data_OK && GPS_command.equals("$GPGGA"))" block - - // we'll fall through to here (instead of returning) when we've read a complete - // sentence, but it doesn't have navigational information (for example, an antenna - // status record). - - } - - } diff --git a/Homework 3/Question 1 Proof/GPS_test_code.ino b/Homework 3/Question 1 Proof/GPS_test_code.ino deleted file mode 100644 index 02fbb7cb1fa9e593ea3a5e63c12698c95977fee9..0000000000000000000000000000000000000000 --- a/Homework 3/Question 1 Proof/GPS_test_code.ino +++ /dev/null @@ -1,1189 +0,0 @@ -#include <Adafruit_GPS.h> - - /*************************************************** - This file is GPS_p398dlp.ino - - Read from the Adaruit GPS breakout board. - - To use this: see the functions setup and loop, and replace things - there with your own code. - - - You'll want to do Tools -> Serial Monitor, then set the baud rate to 115,200 - if you want to stream GPS data to the serial monitor window. If you only set - the baud rate to 9600 it'll be too slow, and interfere with data transmission - from the GPS device to the Arduino processor. - - Also make sure that Tools -> Port is set to the Arduino's port. - - We are interested in two kinds of "sentences" holding GPS navigational data: one - begins with $GPRMC, which holds "Recommended minimum specific GPS/Transit data." - The other begins with $GPGGA, which holds "Global Positioning System Fix Data." - Both include latitude and longitude. See a description of the formats, below. - - Here is the $GPRMC format: - 0 - 5 $GPRMC - 7 - 8 hour, UTC - 9 - 10 minutes, UTC - 11 - 12 seconds, UTC - 14 - 16 milliseconds - 18 A for navigation data OK, V for navigation data not present. - 20 - 28 latitude x 100, in degrees; F9.4 format - 30 N or S - 32 - 41 longitude x 100, in degrees; F10.4 format - 43 E or W - next speed over the ground, in knots; floating point, 5 characters - (data between 7th and 8th commas) - next course direction, degrees, floating point - (data between 8th and 9th commas) - other stuff too. Two examples, the first with navigation information, the second without: - $GPRMC,135228.000,A,4006.9605,N,08815.4528,W,0.44,336.27,090618,,,A*71 - $GPRMC,135217.000,V,,,,,0.74,222.59,090618,,,N*45 - 1 2 3 4 5 6 7 8 - 012345678901234567890123456789012345678901234567890123456789012345678901234567890 - - Here is the $GPGGA format: - 0 - 5 $GPGGA - 7 - 8 hour, UTC - 9 - 10 minutes, UTC - 11 - 16 seconds, UTC, F6.3 format - 18 - 26 latitude x 100, in degrees; F9.4 format - 28 N or S - 30 - 39 longitude x 100, in degrees; F10.4 format - 41 E or W - 43 fix quality: 0 for no fix, 1 for GPS, 2 for DGPS. - 45 - 46 number of satellites - 48 - 51 horizontal dilution of precision - 53 - 57 altitude above sea level - 59 M for altitude in meters - other stuff too. Two examples, the first with navigation information, the second without: - $GPGGA,135224.000,4006.9611,N,08815.4523,W,1,07,1.11,211.7,M,-33.9,M,,*53 - $GPGGA,135217.000,,,,,0,07,,,M,,M,,*7C - 1 2 3 4 5 6 7 8 - 012345678901234567890123456789012345678901234567890123456789012345678901234567890 - - Set GPSECHO1 and GPSECHO2 to 'false' to turn off echoing the GPS data to the Serial console - that are useful for debugging. Set GPSECHO3 to 'false' to prevent final navigation result - from being printed to monitor. Set one or more to 'true' if you want to debug and listen - to the raw GPS sentences. GPSECHO1 yields more verbose echoing than GPSECHO2. - - George Gollin - University of Illinois - September 2018 - -***************************************************/ - -////////////////////////////////////////////////////////////////////// -/////////////////////// global parameters //////////////////////////// -////////////////////////////////////////////////////////////////////// - -/////////////////////////// LCD parameters /////////////////////////// - -#include <LiquidCrystal.h> - -// The LCD is a GlobalFontz 16 x 2 device. - -// initialize the LCD library by associating LCD interface pins -// with the arduino pins to which they are connected. first define -// the pin numbers: reset (rs), enable (en), etc. -const int rs = 12, en = 11, d4 = 36, d5 = 34, d6 = 32, d7 = 30; - -// instantiate an LCD object named "lcd" now. We can use its class -// functions to do good stuff, e.g. lcd.print("the text"). -LiquidCrystal lcd(rs, en, d4, d5, d6, d7); - -// total number of characters in one line of the LCD display -#define LCDWIDTH 16 - -//////////////////////////// keypad parameters //////////////////////////// - -#include <Keypad.h> - -// keypad has four rows and three columns. pushing one key connects together -// the corresponding row and column pins. - -const byte ROWS = 4; -const byte COLS = 3; - -// what they keys actually stand for: -char keys[ROWS][COLS] = { -{'1','2','3'}, -{'4','5','6'}, -{'7','8','9'}, -{'*','0','#'} -}; - -// I am using an Arduino Mega 2560 with a number of breakout boards. -// I have the following pin assignments in order to allow the column -// pins to generate interrupts, if I should decide to take awareness of -// the keypad this way. Note that there might be complicated interactions -// between interrupts used to read the microphone's ADC channel and keypad -// interrupts. - -// Arduino pins looking at the three column pins: -byte colPins[COLS] = {2, 3, 18}; -// Arduino pins looking at the four row pins: -byte rowPins[ROWS] = {31, 33, 35, 37}; - -// instantiate a keypad object. -Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); - -// character returned when I query the keypad (might be empty) -char query_keypad_char = NO_KEY; - -// last non-null character read from keypad -char last_key_char = NO_KEY; - -////////////////////////// DS3231 real time clock parameters //////////////////////// - -// this is an I2C device on an Adafruit breakout board. It is a cute little thing -// with a backup battery. - -#include "RTClib.h" - -// instantiate a real time clock object named "rtc": -RTC_DS3231 rtc; - -// names of the days of the week: -char daysOfTheWeek[7][4] = - {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; - -// declare type for a few RTC-related global variables -int RTC_hour, RTC_minute, RTC_second; -int RTC_year, RTC_month, RTC_day_of_month; - - -// have we already set the RTC clock from the GPS? -bool already_set_RTC_from_GPS; - -/////////////////////////////// GPS parameters ///////////////////////////// - -// Set GPSECHO1 and GPSECHO2 to 'false' to turn off echoing the GPS data to the Serial console -// that are useful for debugging. Set GPSECHO3 to 'false' to prevent final navigation result -// from being printed to monitor. Set one or more to 'true' if you want to debug and listen -//to the raw GPS sentences. GPSECHO1 yields more verbose echoing than GPSECHO2. -#define GPSECHO1 false -#define GPSECHO2 false -#define GPSECHO3 false - -// get the header file in which lots of things are defined: -#include <Adafruit_GPS.h> - -// also define some more stuff relating to update rates. See -// https://blogs.fsfe.org/t.kandler/2013/11/17/set-gps-update- -// rate-on-arduino-uno-adafruit-ultimate-gps-logger-shield/ -#define PMTK_SET_NMEA_UPDATE_10SEC "$PMTK220,10000*2F" -#define PMTK_SET_NMEA_UPDATE_5SEC "$PMTK220,5000*2F" -#define PMTK_SET_NMEA_UPDATE_1HZ "$PMTK220,1000*1F" -#define PMTK_SET_NMEA_UPDATE_2HZ "$PMTK220,500*2B" -#define PMTK_SET_NMEA_UPDATE_5HZ "$PMTK220,200*2C" - -// let's use the Arduino's second serial port to communicate with the GPS device. -#define GPSSerial Serial2 - -// Connect to the GPS via the Arduino's hardware port -Adafruit_GPS GPS(&GPSSerial); - -// we don't expect a valid GPS "sentence" to be longer than this... -#define GPSMAXLENGTH 120 -// or shorter than this: -#define GPSMINLENGTH 55 - -// last sentence read from the GPS: -char* GPS_sentence; - -// we'll also want to convert the character array to a string for convenience -String GPS_sentence_string; - -String GPS_command; - -// pointers into parts of a GPRMC GPS data sentence: - -const int GPRMC_hour_index1 = 8; -const int GPRMC_hour_index2 = GPRMC_hour_index1 + 2; - -const int GPRMC_minutes_index1 = GPRMC_hour_index2; -const int GPRMC_minutes_index2 = GPRMC_minutes_index1 + 2; - -const int GPRMC_seconds_index1 = GPRMC_minutes_index2; -const int GPRMC_seconds_index2 = GPRMC_seconds_index1 + 2; - -const int GPRMC_milliseconds_index1 = GPRMC_seconds_index2 + 1; // skip the decimal point -const int GPRMC_milliseconds_index2 = GPRMC_milliseconds_index1 + 3; - -const int GPRMC_AV_code_index1 = 19; -const int GPRMC_AV_code_index2 = GPRMC_AV_code_index1 + 1; - -const int GPRMC_latitude_1_index1 = 21; -const int GPRMC_latitude_1_index2 = GPRMC_latitude_1_index1 + 4; - -const int GPRMC_latitude_2_index1 = GPRMC_latitude_1_index2 + 1; // skip the decimal point -const int GPRMC_latitude_2_index2 = GPRMC_latitude_2_index1 + 4; - -const int GPRMC_latitude_NS_index1 = 31; -const int GPRMC_latitude_NS_index2 = GPRMC_latitude_NS_index1 + 1; - -const int GPRMC_longitude_1_index1 = 33; -const int GPRMC_longitude_1_index2 = GPRMC_longitude_1_index1 + 5; // 0 - 180 so we need an extra digit - -const int GPRMC_longitude_2_index1 = GPRMC_longitude_1_index2 + 1; // skip the decimal point -const int GPRMC_longitude_2_index2 = GPRMC_longitude_2_index1 + 4; - -const int GPRMC_longitude_EW_index1 = 44; -const int GPRMC_longitude_EW_index2 = GPRMC_longitude_EW_index1 + 1; - -// pointers into a GPGGA GPS data sentence: - -const int GPGGA_hour_index1 = 8; -const int GPGGA_hour_index2 = GPGGA_hour_index1 + 2; - -const int GPGGA_minutes_index1 = GPGGA_hour_index2; -const int GPGGA_minutes_index2 = GPGGA_minutes_index1 + 2; - -const int GPGGA_seconds_index1 = GPGGA_minutes_index2; -const int GPGGA_seconds_index2 = GPGGA_seconds_index1 + 2; - -const int GPGGA_milliseconds_index1 = GPGGA_seconds_index2 + 1; // skip the decimal point -const int GPGGA_milliseconds_index2 = GPGGA_milliseconds_index1 + 3; - -const int GPGGA_latitude_1_index1 = 19; -const int GPGGA_latitude_1_index2 = GPGGA_latitude_1_index1 + 4; - -const int GPGGA_latitude_2_index1 = GPGGA_latitude_1_index2 + 1; // skip the decimal point -const int GPGGA_latitude_2_index2 = GPGGA_latitude_2_index1 + 4; - -const int GPGGA_latitude_NS_index1 = 29; -const int GPGGA_latitude_NS_index2 = GPGGA_latitude_NS_index1 + 1; - -const int GPGGA_longitude_1_index1 = 31; -const int GPGGA_longitude_1_index2 = GPGGA_longitude_1_index1 + 5; // 0 - 180 so we need an extra digit - -const int GPGGA_longitude_2_index1 = GPGGA_longitude_1_index2 + 1; // skip the decimal point -const int GPGGA_longitude_2_index2 = GPGGA_longitude_2_index1 + 4; - -const int GPGGA_longitude_EW_index1 = 42; -const int GPGGA_longitude_EW_index2 = GPGGA_longitude_EW_index1 + 1; - -const int GPGGA_fix_quality_index1 = 44; -const int GPGGA_fix_quality_index2 = GPGGA_fix_quality_index1 + 1; - -const int GPGGA_satellites_index1 = 46; -const int GPGGA_satellites_index2 = GPGGA_satellites_index1 + 2; - -// keep track of how many times we've read a character from the GPS device. -long GPS_char_reads = 0; - -// bail out if we exceed the following number of attempts. when set to 1,000,000 this corresponds -// to about 6 seconds. we need to do this to keep an unresponsive GPS device from hanging the program. -const long GPS_char_reads_maximum = 1000000; - -// define some of the (self-explanatory) GPS data variables. Times/dates are UTC. -String GPS_hour_string; -String GPS_minutes_string; -String GPS_seconds_string; -String GPS_milliseconds_string; -int GPS_hour; -int GPS_minutes; -int GPS_seconds; -int GPS_milliseconds; - -// this one tells us about data validity: A is good, V is invalid. -String GPS_AV_code_string; - -// latitude data -String GPS_latitude_1_string; -String GPS_latitude_2_string; -String GPS_latitude_NS_string; -int GPS_latitude_1; -int GPS_latitude_2; - -// longitude data -String GPS_longitude_1_string; -String GPS_longitude_2_string; -String GPS_longitude_EW_string; -int GPS_longitude_1; -int GPS_longitude_2; - -// velocity information; speed is in knots! -String GPS_speed_knots_string; -String GPS_direction_string; -float GPS_speed_knots; -float GPS_direction; - -String GPS_date_string; - -String GPS_fix_quality_string; -String GPS_satellites_string; -int GPS_fix_quality; -int GPS_satellites; - -String GPS_altitude_string; -float GPS_altitude; - -////////////////////////////////////////////////////////////////////// -//////////////////// end of global parameters //////////////////////// -////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////// -///////////////////////// setup function ///////////////////////////// -////////////////////////////////////////////////////////////////////// - -void setup() -{ - - // setup is run once, immediately after the program is downloaded into - // the Arduino. - - /////////////////// serial port for serial monitor window /////////////////// - - // set to 115,200 baud so that we don't cause problems associated with reading - // and reporting GPS data. - Serial.begin(115200); - - /////////////////////////// LCD setup //////////////////////////// - - // set up the LCD's number of columns and rows, then print a message: - lcd.begin(16, 2); - LCD_message("P398DLP GPS data", "reader/parser "); - - // delay a bit so I have time to see the display. - delay(1000); - -/////////////////////////// DS3231 real time clock setup ///////////////////////// - - // turn on the RTC and check that it is talking to us. - - if (! rtc.begin()) { - - // uh oh, it's not talking to us. - LCD_message("DS3231 RTC", "unresponsive"); - // delay 5 seconds so that user can read the display - delay(5000); - - } else { - - if (rtc.lostPower()) { - - LCD_message("DS3231 RTC lost", "power. Set to..."); - - // Set the RTC with an explicit date & time: September 1, 1988, 7:37:00 am - rtc.adjust(DateTime(1988, 9, 1, 7, 37, 0)); - - } - } - - // set flag that we haven't already set the RTC clock from the GPS - already_set_RTC_from_GPS = false; - - // ask user for year, month, day of the month. see - // https://www.arduino.cc/en/Tutorial.StringToIntExample - - Serial.println("Please enter the year (e.g. 2018) now."); - - String inString = ""; // string to hold input - int inChar = 12345; - - // did we NOT just get a new line character? - while (inChar != '\n' and inChar != '\r') { - - // see if there's any new input. - while (Serial.available() > 0) { - - // read the input character - inChar = Serial.read(); - - if (isDigit(inChar)) { - // convert the incoming byte to a char and add it to the string: - inString += (char)inChar; - } - - // if you get a newline, print the string, then the string's value: - if (inChar == '\n' or inChar == '\r') { - RTC_year = inString.toInt(); - // clear the string for new input: - inString = ""; - } - } - } - - Serial.println("Please enter the month (e.g. 1 for January) now."); - - inString = ""; // string to hold input - inChar = 12345; - - // did we NOT just get a new line character? - while (inChar != '\n' and inChar != '\r') { - - // see if there's any new input. - while (Serial.available() > 0) { - - // read the input character - inChar = Serial.read(); - - if (isDigit(inChar)) { - // convert the incoming byte to a char and add it to the string: - inString += (char)inChar; - } - - // if you get a newline, print the string, then the string's value: - if (inChar == '\n' or inChar == '\r') { - RTC_month = inString.toInt(); - // clear the string for new input: - inString = ""; - } - } - } - - Serial.println("Please enter the day of the month (e.g. 1 for January 1st) now."); - - inString = ""; // string to hold input - inChar = 12345; - - // did we NOT just get a new line character? - while (inChar != '\n' and inChar != '\r') { - - // see if there's any new input. - while (Serial.available() > 0) { - - // read the input character - inChar = Serial.read(); - - if (isDigit(inChar)) { - // convert the incoming byte to a char and add it to the string: - inString += (char)inChar; - } - - // if you get a newline, print the string, then the string's value: - if (inChar == '\n' or inChar == '\r') { - RTC_day_of_month = inString.toInt(); - // clear the string for new input: - inString = ""; - } - } - } - - Serial.print("you've entered the year, month, day as "); Serial.print(RTC_year); Serial.print("/"); - Serial.print(RTC_month); Serial.print("/"); - Serial.println(RTC_day_of_month); - -////////////////////////////////// GPS setup ////////////////////////////// - - // If you want to see a detailed report of the GPS information, open a serial - // monitor window by going to the Tools -> Serial Monitor menu, then checking - // the Autoscroll box at the bottom left of the window, and setting the baud rate - // to 115200 baud. - - // once we've set up the GPS it will free-run: it has its own built-in microprocessor. - - // 9600 NMEA is the default communication and baud rate for Adafruit MTK GPS units. - // NMEA is "National Marine Electronics Association." - // Note that this serial communication path is different from the one driving the serial - // monitor window on your laptop, which should be running at 115,200 baud. - GPS.begin(9600); - - // turn on RMC (recommended minimum) and GGA (fix data, including altitude) - GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); - - // uncomment this line to turn on only the "minimum recommended" data: - // GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY); - - // Set the update rate to once per second. Faster than this might make it hard for - // the serial communication line to keep up. You'll want to check that the - // faster read rates work reliably for you before using them. - - // what the heck... let's try 5 Hz. - //GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); - // GPS.sendCommand(PMTK_SET_NMEA_UPDATE_2HZ); - GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ); - // GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ); - - // Request updates on antenna status, comment out to keep quiet. - // GPS.sendCommand(PGCMD_ANTENNA); - - // Ask for firmware version, write this to the serial monitor. Comment out to keep quiet. - // GPSSerial.println(PMTK_Q_RELEASE); - -///////////////////////////////////////////////////////////////////////// - -} - - -////////////////////////////////////////////////////////////////////// -//////////////////////////// loop function /////////////////////////// -////////////////////////////////////////////////////////////////////// - -void loop() -{ - - // loop function is executed repeatedly after the setup function finishes. - - // request GPS position information - GPS_query(); - - // now print some of it: the data are stored in global variables and can - // be accessed here. variable names are self explanatory. - Serial.print("\nGPS_hour (UTC) = "); Serial.print(GPS_hour); - Serial.print(" GPS_minutes = "); Serial.print(GPS_minutes); - Serial.print(" GPS_seconds = "); Serial.print(GPS_seconds); - Serial.print(" GPS_milliseconds = "); Serial.println(GPS_milliseconds); - - Serial.print("100 x lattitude and longitude (degrees): "); - Serial.print(GPS_latitude_1_string); Serial.print("."); Serial.print(GPS_latitude_2_string); - Serial.print(GPS_latitude_NS_string); Serial.print(" "); - Serial.print(GPS_longitude_1_string); Serial.print("."); Serial.print(GPS_longitude_2_string); - Serial.println(GPS_longitude_EW_string); - - Serial.print("GPS_speed_knots = "); Serial.print(GPS_speed_knots); - Serial.print(" GPS speed, mph = "); Serial.print(GPS_speed_knots * 1.15078); - Serial.print(" direction (degrees) = "); Serial.println(GPS_direction); - - // Serial.print("try GPS.now... "); Serial.println(GPS.now); - - delay(500); - - // if we have GPS data and haven't yet set the RTC, set the clock now. - if( (GPS_hour != 0 or GPS_minutes != 0 or GPS_seconds != 0 or GPS_milliseconds != 0) - and !already_set_RTC_from_GPS) { - - // we have something coming in from the GPS, and haven't yet set the real time - // clock, so set the RTC now using the last data sentence from the GPS. This isn't - // the most accurate way to do it, but it ought to get us within a second of the - // correct time. - - // To set the RTC with an explicit date & time: September 1, 1988, 7:37:00 am do this: - // rtc.adjust(DateTime(1988, 9, 1, 7, 37, 0)); - - rtc.adjust(DateTime(RTC_year, RTC_month, RTC_day_of_month, GPS_hour, GPS_minutes, GPS_seconds)); - already_set_RTC_from_GPS = true; - - } - - // talk to the realtime clock and print its information. note that unless you've - // synchronized the RTC and GPS, they won't necessarily agree. - DS3231_query(); - - Serial.print("RTC_hour = "); Serial.print(RTC_hour); - Serial.print(" RTC_minute = "); Serial.print(RTC_minute); - Serial.print(" RTC_second = "); Serial.println(RTC_second); - - delay(500); - -} - - -////////////////////////////////////////////////////////////////////// -////////////////////////// LCD_message function ////////////////////// -////////////////////////////////////////////////////////////////////// - -void LCD_message(String line1, String line2) -{ - // write two lines (of 16 characters each, maximum) to the LCD display. - // I assume an object named "lcd" has been created already, has been - // initialized in setup, and is global. - - // set the cursor to the beginning of the first line, clear the line, then write. - lcd.setCursor(0, 0); - lcd.print(" "); - lcd.setCursor(0, 0); - lcd.print(line1); - - // now do the next line. - lcd.setCursor(0, 1); - lcd.print(" "); - lcd.setCursor(0, 1); - lcd.print(line2); - - return; -} - - -////////////////////////////////////////////////////////////////////// -////////////////////// DS3231_query function ///////////////////////// -////////////////////////////////////////////////////////////////////// - -void DS3231_query() -{ - // read from the DS3231 real time clock. - - // these were already declared as global variables. - // int RTC_minute, RTC_second; - - // we have already instantiated the device as an object named "now" so we can - // call its class functions. - DateTime now = rtc.now(); - - lcd.setCursor(0, 0); - lcd.print("Realtime clock "); - - // write time information to LCD. Year, etc. first, after setting LCD to second line. - lcd.setCursor(0, 1); - lcd.print(" "); - lcd.setCursor(0, 1); - lcd.print(now.year(), DEC); - lcd.print('/'); - lcd.print(now.month(), DEC); - lcd.print('/'); - lcd.print(now.day(), DEC); - - // delay a second - delay(1000); - - // now display the day of the week and time. - RTC_hour = now.hour(); - RTC_minute = now.minute(); - RTC_second = now.second(); - - lcd.setCursor(0, 1); - lcd.print(" "); - lcd.setCursor(0, 1); - lcd.print(daysOfTheWeek[now.dayOfTheWeek()]); - lcd.print(". "); - - lcd.print(RTC_hour, DEC); - lcd.print(':'); - if (RTC_minute < 10) {lcd.print('0');} - lcd.print(RTC_minute, DEC); - lcd.print(':'); - if (RTC_second < 10) {lcd.print('0');} - lcd.print(RTC_second, DEC); - - // there are other functions available, such as - // now.unixtime(); - // DateTime future (now + TimeSpan(7,12,30,6)); - // future.year(); etc. etc. - -} - - - -////////////////////////////////////////////////////////////////////// -////////////////////// GPS_query function ///////////////////////// -////////////////////////////////////////////////////////////////////// - -int GPS_query() -{ - - // return 0 if we found good GPS navigational data and -1 if not. - - // The GPS device has its own microprocessor and, once we have loaded its parameters, - // free-runs at a 1 Hz sampling rate. We do not trigger its registration of - // latitude and longitude, rather we just read from it the last data record - // it has stored. And we do it one character at a time! - - // I will keep reading from the GPS until I have a complete sentence carrying valid - // navigational data, with a maximum number of reads to prevent the program from hanging. Once - // the GPS reports its updates latitude/longitude information, we'll push this to the - // LCD display, then return to the main loop. - - // zero out (or set to defaults) values returned by the GPS device in case we can't - // get it to respond. - GPS_hour = GPS_minutes = GPS_seconds = GPS_milliseconds = 0; - - GPS_AV_code_string = "V"; - - GPS_latitude_1 = GPS_latitude_2 = 0; - GPS_latitude_NS_string = "x"; - - GPS_longitude_1 = GPS_longitude_2 = 0; - GPS_longitude_EW_string = "y"; - - GPS_speed_knots = 0.; - GPS_direction = 0.; - - GPS_date_string = "000000"; - - GPS_fix_quality = GPS_satellites = 0; - - GPS_altitude = 0.; - - // initialize the number-of-reads counter since we might find ourselves - // with an unparseable data record, or an unresponsive GPS, and want to keep trying. - // This will let me protect against the data logger's program hanging. - GPS_char_reads = 0; - - // set a flag saying we want to keep trying; we'll use this to keep looking for - // useful navigation when the GPS is working fine, but still looking for satellites. - bool keep_trying = true; - - // Stay inside the following loop until we've read a complete GPS sentence with - // good navigational data, or else the loop times out. With GPS_char_reads_maximum - // set to a million this'll take about 6 seconds to time out. - - while (true) { - - // if we get back to this point but the keep_trying flag is false, we'll want - // to declare failure and quit. - - if(!keep_trying) return -1; - - // this gets the last sentence read from GPS and clears a newline flag in the Adafruit - // library code. - GPS_sentence = GPS.lastNMEA(); - - while(GPS_char_reads <= GPS_char_reads_maximum) - { - - // try to read a single character from the GPS device. - char single_GPS_char = GPS.read(); - - // bump the number of times we've tried to read from the GPS. - GPS_char_reads++; - - // now ask if we've received a complete data sentence. If yes, break - // out of this loop. - - if(GPS.newNMEAreceived()) break; - - } - - - // if we hit the limit on the number of character reads we'e tried, print a message and bail out. - if (GPS_char_reads >= GPS_char_reads_maximum) - { - - keep_trying = false; - - Serial.println("GPS navigation data not yet available. Try again later."); - LCD_message("GPS navigation ", "data unavailable"); - - return -1; - - } - - // get the last complete sentence read from GP; this automatically clears a newline flag inside - // the Adafruit library code. - GPS_sentence = GPS.lastNMEA(); - - // convert GPS data sentence from a character array to a string. - GPS_sentence_string = String(GPS_sentence); - - // now do a cursory check that the sentence we've just read is OK. Check that there is only - // one $, as the first character in the sentence, and that there's an asterisk (which commes - // immediately before the checksum). - - // sentence starts with a $? - bool data_OK = GPS_sentence_string.charAt(0) == '$'; - - // sentence contains no other $? The indexOf call will return -1 if $ is not found. - data_OK = data_OK && (GPS_sentence_string.indexOf('$', 2) < 0); - - // now find that asterisk... - data_OK = data_OK && (GPS_sentence_string.indexOf('*', 0) > 0); - - if (GPSECHO1) - { - Serial.println("\n******************\njust received a complete sentence, so parse stuff. Sentence is"); - Serial.println(GPS_sentence_string); - } - - // now parse the GPS sentence. I am only interested in sentences that begin with - // $GPGGA ("GPS fix data") or $GPRMC ("recommended minimum specific GPS/Transit data"). - - if(GPSECHO1) - { - Serial.print("length of GPS_sentence_string just received..."); - Serial.println(GPS_sentence_string.length()); - } - - // now get substring holding the GPS command. Only proceed if it is $GPRMC or $GPGGA. - GPS_command = GPS_sentence_string.substring(0, 6); - - // also trim it to make sure we don't have hidden stuff or white space sneaking in. - GPS_command.trim(); - - if(GPSECHO1) - { - Serial.print("GPS command is "); Serial.println(GPS_command); - } - - // if data_OK is true then we have a good sentence. but we also need the sentence - // to hold navigational data we can use, otherwise we'll want to keep listening. - // we can only work with GPRMC and GPGGA sentences. - - bool command_OK = GPS_command.equals("$GPRMC") || GPS_command.equals("$GPGGA"); - - // if we have a sentence that, upon cursory inspection, is well formatted AND might - // hold navigational data, continue to parse the sentence. If the GPS device - // hasn't found any satellites yet, we'll want to go back to the top of the loop - // to keep trying, rather than declaring defeat and returning. - - ////////////////////////////////////////////////////////////////////// - /////////////////////////// GPRMC sentence /////////////////////////// - ////////////////////////////////////////////////////////////////////// - - if (data_OK && GPS_command.equals("$GPRMC")) - { - - if(GPSECHO2) - { - Serial.print("\nnew GPS sentence: "); Serial.println(GPS_sentence_string); - } - - // parse the time. these are global variables, already declared. - - GPS_hour_string = GPS_sentence_string.substring(GPRMC_hour_index1, GPRMC_hour_index2); - GPS_minutes_string = GPS_sentence_string.substring(GPRMC_minutes_index1, GPRMC_minutes_index2); - GPS_seconds_string = GPS_sentence_string.substring(GPRMC_seconds_index1, GPRMC_seconds_index2); - GPS_milliseconds_string = GPS_sentence_string.substring(GPRMC_milliseconds_index1, - GPRMC_milliseconds_index2); - GPS_AV_code_string = GPS_sentence_string.substring(GPRMC_AV_code_index1, GPRMC_AV_code_index2); - - GPS_hour = GPS_hour_string.toInt(); - GPS_minutes = GPS_minutes_string.toInt(); - GPS_seconds = GPS_seconds_string.toInt(); - GPS_milliseconds = GPS_milliseconds_string.toInt(); - - if(GPSECHO2) - { - Serial.print("Time (UTC) = "); Serial.print(GPS_hour); Serial.print(":"); - Serial.print(GPS_minutes); Serial.print(":"); - Serial.print(GPS_seconds); Serial.print("."); - Serial.println(GPS_milliseconds); - Serial.print("A/V code is "); Serial.println(GPS_AV_code_string); - } - - // now see if the data are valid: we'll expect an "A" as the AV code string. - // We also expect an asterisk two characters from the end. Also check that the sentence - // is at least as long as the minimum length expected. - - data_OK = GPS_AV_code_string == "A"; - - // now look for the asterisk after trimming any trailing whitespace in the GPS sentence. - // the asterisk preceeds the sentence's checksum information, which I won't bother to check. - int asterisk_should_be_here = GPS_sentence_string.length() - 4; - - data_OK = data_OK && (GPS_sentence_string.charAt(asterisk_should_be_here) == '*'); - - if(GPSECHO2) - { - Serial.print("expected asterisk position "); Serial.print(asterisk_should_be_here); - Serial.print(" at that position: "); Serial.println(GPS_sentence_string.charAt(asterisk_should_be_here)); - } - - // now check that the sentence is not too short. - data_OK = data_OK && (GPS_sentence_string.length() >= GPSMINLENGTH); - - if (!data_OK) - { - - keep_trying = true; - - if (GPSECHO1) - { - Serial.print("GPS sentence not good for navigation: "); Serial.println(GPS_sentence_string); - Serial.println("I will keep trying..."); - } - - lcd.setCursor(0, 0); - lcd.print("GPS navigation "); - lcd.setCursor(0, 1); - lcd.print("data not present"); - - } - - // if data are not good, go back to the top of the loop by breaking out of this if block. - // we've already set keep_trying to be true. - - if (!data_OK) break; - - // so far so good, so keep going... - - // now parse latitude - - GPS_latitude_1_string = GPS_sentence_string.substring(GPRMC_latitude_1_index1, - GPRMC_latitude_1_index2); - GPS_latitude_2_string = GPS_sentence_string.substring(GPRMC_latitude_2_index1, - GPRMC_latitude_2_index2); - GPS_latitude_NS_string = GPS_sentence_string.substring(GPRMC_latitude_NS_index1, - GPRMC_latitude_NS_index2); - - GPS_latitude_1 = GPS_latitude_1_string.toInt(); - GPS_latitude_2 = GPS_latitude_2_string.toInt(); - - if(GPSECHO2) - { - Serial.print("Latitude x 100 = "); Serial.print(GPS_latitude_1); Serial.print("."); - Serial.print(GPS_latitude_2); Serial.println(GPS_latitude_NS_string); - } - - // now parse longitude - - GPS_longitude_1_string = GPS_sentence_string.substring(GPRMC_longitude_1_index1, - GPRMC_longitude_1_index2); - GPS_longitude_2_string = GPS_sentence_string.substring(GPRMC_longitude_2_index1, - GPRMC_longitude_2_index2); - GPS_longitude_EW_string = GPS_sentence_string.substring(GPRMC_longitude_EW_index1, - GPRMC_longitude_EW_index2); - - GPS_longitude_1 = GPS_longitude_1_string.toInt(); - GPS_longitude_2 = GPS_longitude_2_string.toInt(); - - if(GPSECHO2) - { - Serial.print("Longitude x 100 = "); Serial.print(GPS_longitude_1); Serial.print("."); - Serial.print(GPS_longitude_2); Serial.println(GPS_longitude_EW_string); - } - - // now parse speed and direction. we'll need to locate the 7th and 8th commas in the - // data sentence to do this. so use the indexOf function to find them. - // it returns -1 if string wasn't found. the number of digits is not uniquely defined - // so we need to find the fields based on the commas separating them from others. - - int comma_A_index = GPRMC_longitude_EW_index2; - int comma_B_index = GPS_sentence_string.indexOf(",", comma_A_index + 1); - int comma_C_index = GPS_sentence_string.indexOf(",", comma_B_index + 1); - - GPS_speed_knots_string = GPS_sentence_string.substring(comma_A_index + 1, comma_B_index); - GPS_direction_string = GPS_sentence_string.substring(comma_B_index + 1, comma_C_index); - - GPS_speed_knots = GPS_speed_knots_string.toFloat(); - GPS_direction = GPS_direction_string.toFloat(); - - if(GPSECHO2) - { - Serial.print("Speed (knots) = "); Serial.println(GPS_speed_knots); - Serial.print("Direction (degrees) = "); Serial.println(GPS_direction); - } - - // now get the (UTC) date, in format DDMMYY, e.g. 080618 for 8 June 2018. - GPS_date_string = GPS_sentence_string.substring(comma_C_index+ + 1, comma_C_index + 7); - - if(GPSECHO2) - { - Serial.print("date, in format ddmmyy = "); Serial.println(GPS_date_string); - } - - // Write message to LCD now. It will look like this (no satellite data in this record): - // Sats: 4006.9539N - // N/A 08815.4431W - - lcd.setCursor(0, 0); - lcd.print("Sats: "); - lcd.setCursor(6, 0); - lcd.print(GPS_latitude_1_string); lcd.print("."); lcd.print(GPS_latitude_2_string); - lcd.print(GPS_latitude_NS_string); - - lcd.setCursor(0, 1); - lcd.print("N/A "); - lcd.setCursor(5, 1); - lcd.print(GPS_longitude_1_string); lcd.print("."); lcd.print(GPS_longitude_2_string); - lcd.print(GPS_longitude_EW_string); - - // print a summary of the data and parsed results: - if(GPSECHO3) - { - Serial.print("GPS sentence: "); Serial.println(GPS_sentence_string); - - Serial.print("Time (UTC) = "); Serial.print(GPS_hour); Serial.print(":"); - Serial.print(GPS_minutes); Serial.print(":"); - Serial.print(GPS_seconds); Serial.print("."); - Serial.println(GPS_milliseconds); - - Serial.print("Latitude x 100 = "); Serial.print(GPS_latitude_1); Serial.print("."); - Serial.print(GPS_latitude_2); Serial.print(" "); Serial.print(GPS_latitude_NS_string); - - Serial.print(" Longitude x 100 = "); Serial.print(GPS_longitude_1); Serial.print("."); - Serial.print(GPS_longitude_2); Serial.print(" "); Serial.println(GPS_longitude_EW_string); - - Serial.print("Speed (knots) = "); Serial.print(GPS_speed_knots); - Serial.print(" Direction (degrees) = "); Serial.println(GPS_direction); - - Serial.println("There is no satellite or altitude information in a GPRMC data sentence."); - - } - - // all done with this sentence, so return. - return 0; - - } // end of "if (data_OK && GPS_command.equals("$GPRMC"))" block - - ////////////////////////////////////////////////////////////////////// - /////////////////////////// GPGGA sentence /////////////////////////// - ////////////////////////////////////////////////////////////////////// - - if (data_OK && GPS_command.equals("$GPGGA")) - { - - if(GPSECHO2) - { - Serial.print("\nnew GPS sentence: "); Serial.println(GPS_sentence_string); - } - - // parse the time - - GPS_hour_string = GPS_sentence_string.substring(GPGGA_hour_index1, GPGGA_hour_index2); - GPS_minutes_string = GPS_sentence_string.substring(GPGGA_minutes_index1, GPGGA_minutes_index2); - GPS_seconds_string = GPS_sentence_string.substring(GPGGA_seconds_index1, GPGGA_seconds_index2); - GPS_milliseconds_string = GPS_sentence_string.substring(GPGGA_milliseconds_index1, - GPGGA_milliseconds_index2); - - GPS_hour = GPS_hour_string.toInt(); - GPS_minutes = GPS_minutes_string.toInt(); - GPS_seconds = GPS_seconds_string.toInt(); - GPS_milliseconds = GPS_milliseconds_string.toInt(); - - if(GPSECHO2) - { - Serial.print("Time (UTC) = "); Serial.print(GPS_hour); Serial.print(":"); - Serial.print(GPS_minutes); Serial.print(":"); - Serial.print(GPS_seconds); Serial.print("."); - Serial.println(GPS_milliseconds); - } - - // now get the fix quality and number of satellites. - - GPS_fix_quality_string = GPS_sentence_string.substring(GPGGA_fix_quality_index1, - GPGGA_fix_quality_index2); - GPS_satellites_string = GPS_sentence_string.substring(GPGGA_satellites_index1, - GPGGA_satellites_index2); - - int GPS_fix_quality = GPS_fix_quality_string.toInt(); - int GPS_satellites = GPS_satellites_string.toInt(); - - if(GPSECHO2) - { - Serial.print("fix quality (1 for GPS, 2 for DGPS) = "); Serial.println(GPS_fix_quality); - Serial.print("number of satellites = "); Serial.println(GPS_satellites); - } - - // now see if the data are valid: we'll expect a fix, and at least three satellites. - - bool data_OK = (GPS_fix_quality > 0) && (GPS_satellites >= 3); - - // now look for the asterisk. - int asterisk_should_be_here = GPS_sentence_string.length() - 4; - - data_OK = data_OK && (GPS_sentence_string.charAt(asterisk_should_be_here) == '*'); - - // now check that the sentence is not too short. - data_OK = data_OK && (GPS_sentence_string.length() >= GPSMINLENGTH); - - if (!data_OK) - { - - keep_trying = true; - - if (GPSECHO1) - { - Serial.print("GPS sentence not good for navigation: "); Serial.println(GPS_sentence_string); - Serial.println("I will keep trying..."); - } - - lcd.setCursor(0, 0); - lcd.print("GPS navigation "); - lcd.setCursor(0, 1); - lcd.print("data not present"); - - } - - // if data are not good, go back to the top of the loop by breaking out of this if block. - - if (!data_OK) break; - - // so far so good, so keep going... - - // now parse latitude - - String GPS_latitude_1_string = GPS_sentence_string.substring(GPGGA_latitude_1_index1, - GPGGA_latitude_1_index2); - String GPS_latitude_2_string = GPS_sentence_string.substring(GPGGA_latitude_2_index1, - GPGGA_latitude_2_index2); - String GPS_latitude_NS_string = GPS_sentence_string.substring(GPGGA_latitude_NS_index1, - GPGGA_latitude_NS_index2); - - int GPS_latitude_1 = GPS_latitude_1_string.toInt(); - int GPS_latitude_2 = GPS_latitude_2_string.toInt(); - - if(GPSECHO2) - { - Serial.print("Latitude x 100 = "); Serial.print(GPS_latitude_1); Serial.print("."); - Serial.print(GPS_latitude_2); Serial.println(GPS_latitude_NS_string); - } - - // now parse longitude - - String GPS_longitude_1_string = GPS_sentence_string.substring(GPGGA_longitude_1_index1, - GPGGA_longitude_1_index2); - String GPS_longitude_2_string = GPS_sentence_string.substring(GPGGA_longitude_2_index1, - GPGGA_longitude_2_index2); - String GPS_longitude_EW_string = GPS_sentence_string.substring(GPGGA_longitude_EW_index1, - GPGGA_longitude_EW_index2); - - int GPS_longitude_1 = GPS_longitude_1_string.toInt(); - int GPS_longitude_2 = GPS_longitude_2_string.toInt(); - - if(GPSECHO2) - { - Serial.print("Longitude x 100 = "); Serial.print(GPS_longitude_1); Serial.print("."); - Serial.print(GPS_longitude_2); Serial.println(GPS_longitude_EW_string); - } - - // let's skip the "horizontal dilution" figure and go straight for the altitude now. - // this begins two fields to the right of the num,ber of satellites so find this - // by counting commas. use the indexOf function to find them. - int comma_A_index = GPS_sentence_string.indexOf(",", GPGGA_satellites_index2 + 1); - int comma_B_index = GPS_sentence_string.indexOf(",", comma_A_index + 1); - - String GPS_altitude_string = GPS_sentence_string.substring(comma_A_index + 1, comma_B_index); - - float GPS_altitude = GPS_altitude_string.toFloat(); - - if(GPSECHO2) - { - Serial.print("Altitude (meters) = "); Serial.println(GPS_altitude); - } - - // Write message to LCD now. It will look like this: - // Sats: 4006.9539N - // 10 08815.4431W - - lcd.setCursor(0, 0); - lcd.print("Sats: "); - lcd.setCursor(6, 0); - lcd.print(GPS_latitude_1_string); lcd.print("."); lcd.print(GPS_latitude_2_string); - lcd.print(GPS_latitude_NS_string); - - lcd.setCursor(0, 1); - lcd.print(" "); - lcd.setCursor(2, 1); - lcd.print(GPS_satellites); - lcd.setCursor(5, 1); - lcd.print(GPS_longitude_1_string); lcd.print("."); lcd.print(GPS_longitude_2_string); - lcd.print(GPS_longitude_EW_string); - - // print a summary of the data and parsed results: - if(GPSECHO3) - { - Serial.print("GPS sentence: "); Serial.println(GPS_sentence_string); - - Serial.print("Time (UTC) = "); Serial.print(GPS_hour); Serial.print(":"); - Serial.print(GPS_minutes); Serial.print(":"); - Serial.print(GPS_seconds); Serial.print("."); - Serial.println(GPS_milliseconds); - - Serial.print("Latitude x 100 = "); Serial.print(GPS_latitude_1); Serial.print("."); - Serial.print(GPS_latitude_2); Serial.print(" "); Serial.print(GPS_latitude_NS_string); - - Serial.print(" Longitude x 100 = "); Serial.print(GPS_longitude_1); Serial.print("."); - Serial.print(GPS_longitude_2); Serial.print(" "); Serial.println(GPS_longitude_EW_string); - - Serial.print("Speed (knots) = "); Serial.print(GPS_speed_knots); - Serial.print(" Direction (degrees) = "); Serial.println(GPS_direction); - - Serial.print("Number of satellites: "); Serial.print(GPS_satellites); - Serial.print(" Altitude (meters): "); Serial.println(GPS_altitude); - - } - - // all done with this sentence, so return. - return 0; - - } // end of "if (data_OK && GPS_command.equals("$GPGGA"))" block - - // we'll fall through to here (instead of returning) when we've read a complete - // sentence, but it doesn't have navigational information (for example, an antenna - // status record). - - } - - } diff --git a/Homework 3/Question 1 Proof/gps_+_rtc_proof.png b/Homework 3/Question 1 Proof/gps_+_rtc_proof.png deleted file mode 100644 index 7ae76bc8667e9d409d2ffc8847001293829383da..0000000000000000000000000000000000000000 Binary files a/Homework 3/Question 1 Proof/gps_+_rtc_proof.png and /dev/null differ diff --git a/Homework 3/Question 1 Proof/pic+sd+bme_proof.png b/Homework 3/Question 1 Proof/pic+sd+bme_proof.png deleted file mode 100644 index faa3ef2d53f694d9ba9c67cc6b28d60650d0e54c..0000000000000000000000000000000000000000 Binary files a/Homework 3/Question 1 Proof/pic+sd+bme_proof.png and /dev/null differ diff --git a/Homework 3/Question 2/.gitkeep b/Homework 3/Question 2/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/Homework 3/Question 2/IMAGE00.JPG b/Homework 3/Question 2/IMAGE00.JPG deleted file mode 100644 index 3bed0c3478f2f9d1a7d23c5f0d117acb6cbc1090..0000000000000000000000000000000000000000 Binary files a/Homework 3/Question 2/IMAGE00.JPG and /dev/null differ diff --git a/Homework 3/Question 2/data.csv b/Homework 3/Question 2/data.csv deleted file mode 100644 index 3e58ee294e4c819663d27b9508c00fdbbc604dda..0000000000000000000000000000000000000000 --- a/Homework 3/Question 2/data.csv +++ /dev/null @@ -1,7 +0,0 @@ -12:06:03,Feb 9 2023,IMAGE00.JPG,1387,25.98,,,,,,,,,, -12:06:03,Feb 9 2023,IMAGE01.JPG,1809,25.53,,,,,,,,,Mean,Standard Deviation -12:06:03,Feb 9 2023,IMAGE02.JPG,1809,25.13,,,,,,,,,24.92428571,0.612275782 -12:06:03,Feb 9 2023,IMAGE03.JPG,1809,24.8,,,,,,,,,, -12:06:03,Feb 9 2023,IMAGE04.JPG,2041,24.54,,,,,,,,,, -12:06:03,Feb 9 2023,IMAGE05.JPG,2960,24.33,,,,,,,,,, -12:06:03,Feb 9 2023,IMAGE06.JPG,3066,24.16,,,,,,,,,, diff --git a/Homework 3/Question 2/tempvstime.png b/Homework 3/Question 2/tempvstime.png deleted file mode 100644 index ce4d2ba0565f9c893a9349671d7639fbddfdaed5..0000000000000000000000000000000000000000 Binary files a/Homework 3/Question 2/tempvstime.png and /dev/null differ diff --git a/crop/SimData.ipynb b/crop/SimData.ipynb index 434ae9708f4ee276c25c0c80362ef14be4da00d2..4cb9dc0259e04f6b93214104d1ba89434b355b86 100644 --- a/crop/SimData.ipynb +++ b/crop/SimData.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 200, "metadata": {}, "outputs": [], "source": [ @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 201, "metadata": {}, "outputs": [], "source": [ @@ -80,11 +80,16 @@ " # get random beetle image\n", " beetle_id = np.random.randint(0, set_size)\n", " beetle_img = beetle_set[beetle_id]\n", - " \n", " # get random beetle rotation\n", " angle = np.random.randint(0, 360)\n", " beetle_img = beetle_img.rotate(angle, resample=Image.BICUBIC, expand=1)\n", " \n", + " #randomly resize beetle to be smaller as they are much bigger on image\n", + " \n", + " beetle_width, beetle_height = beetle_img.size\n", + " beetle_max = np.max([beetle_width, beetle_height])\n", + " factor = np.random.uniform((height/(5*9))/beetle_max, (height/(4*9))/beetle_max)\n", + " beetle_img = beetle_img.resize((int(factor * beetle_width), int(factor * beetle_height)), resample=Image.BICUBIC)\n", " beetle_width, beetle_height = beetle_img.size\n", " \n", " # get random x,y coords to paste beetle\n", @@ -121,7 +126,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 202, "metadata": {}, "outputs": [], "source": [ @@ -139,7 +144,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 203, "metadata": {}, "outputs": [], "source": [ @@ -154,6 +159,7 @@ " backgrounds.append(bg)\n", " continue\n", " bg = Image.open(file)\n", + " \n", " backgrounds.append(bg);\n", "\n", "beetles = []\n", @@ -168,7 +174,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 204, "metadata": {}, "outputs": [ { @@ -189,7 +195,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 188, "metadata": {}, "outputs": [], "source": [ @@ -201,7 +207,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 189, "metadata": {}, "outputs": [], "source": [ @@ -226,7 +232,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 190, "metadata": {}, "outputs": [ { @@ -242,1247 +248,7 @@ "6\n", "7\n", "8\n", - "9\n", - "10\n", - "11\n", - "12\n", - "13\n", - "14\n", - "15\n", - "16\n", - "17\n", - "18\n", - "19\n", - "20\n", - "21\n", - "22\n", - "23\n", - "24\n", - "25\n", - "26\n", - "27\n", - "28\n", - "29\n", - "30\n", - "31\n", - "32\n", - "33\n", - "34\n", - "35\n", - "36\n", - "37\n", - "38\n", - "39\n", - "40\n", - "41\n", - "42\n", - "43\n", - "44\n", - "45\n", - "46\n", - "47\n", - "48\n", - "49\n", - "50\n", - "51\n", - "52\n", - "53\n", - "54\n", - "55\n", - "56\n", - "57\n", - "58\n", - "59\n", - "60\n", - "61\n", - "62\n", - "63\n", - "64\n", - "65\n", - "66\n", - "67\n", - "68\n", - "69\n", - "70\n", - "71\n", - "72\n", - "73\n", - "74\n", - "75\n", - "76\n", - "77\n", - "78\n", - "79\n", - "80\n", - "81\n", - "82\n", - "83\n", - "84\n", - "85\n", - "86\n", - "87\n", - "88\n", - "89\n", - "90\n", - "91\n", - "92\n", - "93\n", - "94\n", - "95\n", - "96\n", - "97\n", - "98\n", - "99\n", - "100\n", - "101\n", - "102\n", - "103\n", - "104\n", - "105\n", - "106\n", - "107\n", - "108\n", - "109\n", - "110\n", - "111\n", - "112\n", - "113\n", - "114\n", - "115\n", - "116\n", - "117\n", - "118\n", - "119\n", - "120\n", - "121\n", - "122\n", - "123\n", - "124\n", - "125\n", - "126\n", - "127\n", - "128\n", - "129\n", - "130\n", - "131\n", - "132\n", - "133\n", - "134\n", - "135\n", - "136\n", - "137\n", - "138\n", - "139\n", - "140\n", - "141\n", - "142\n", - "143\n", - "144\n", - "145\n", - "146\n", - "147\n", - "148\n", - "149\n", - "150\n", - "151\n", - "152\n", - "153\n", - "154\n", - "155\n", - "156\n", - "157\n", - "158\n", - "159\n", - "160\n", - "161\n", - "162\n", - "163\n", - "164\n", - "165\n", - "166\n", - "167\n", - "168\n", - "169\n", - "170\n", - "171\n", - "172\n", - "173\n", - "174\n", - "175\n", - "176\n", - "177\n", - "178\n", - "179\n", - "180\n", - "181\n", - "182\n", - "183\n", - "184\n", - "185\n", - "186\n", - "187\n", - "188\n", - "189\n", - "190\n", - "191\n", - "192\n", - "193\n", - "194\n", - "195\n", - "196\n", - "197\n", - "198\n", - "199\n", - "200\n", - "201\n", - "202\n", - "203\n", - "204\n", - "205\n", - "206\n", - "207\n", - "208\n", - "209\n", - "210\n", - "211\n", - "212\n", - "213\n", - "214\n", - "215\n", - "216\n", - "217\n", - "218\n", - "219\n", - "220\n", - "221\n", - "222\n", - "223\n", - "224\n", - "225\n", - "226\n", - "227\n", - "228\n", - "229\n", - "230\n", - "231\n", - "232\n", - "233\n", - "234\n", - "235\n", - "236\n", - "237\n", - "238\n", - "239\n", - "240\n", - "241\n", - "242\n", - "243\n", - "244\n", - "245\n", - "246\n", - "247\n", - "248\n", - "249\n", - "250\n", - "251\n", - "252\n", - "253\n", - "254\n", - "255\n", - "256\n", - "257\n", - "258\n", - "259\n", - "260\n", - "261\n", - "262\n", - "263\n", - "264\n", - "265\n", - "266\n", - "267\n", - "268\n", - "269\n", - "270\n", - "271\n", - "272\n", - "273\n", - "274\n", - "275\n", - "276\n", - "277\n", - "278\n", - "279\n", - "280\n", - "281\n", - "282\n", - "283\n", - "284\n", - "285\n", - "286\n", - "287\n", - "288\n", - "289\n", - "290\n", - "291\n", - "292\n", - "293\n", - "294\n", - "295\n", - "296\n", - "297\n", - "298\n", - "299\n", - "300\n", - "301\n", - "302\n", - "303\n", - "304\n", - "305\n", - "306\n", - "307\n", - "308\n", - "309\n", - "310\n", - "311\n", - "312\n", - "313\n", - "314\n", - "315\n", - "316\n", - "317\n", - "318\n", - "319\n", - "320\n", - "321\n", - "322\n", - "323\n", - "324\n", - "325\n", - "326\n", - "327\n", - "328\n", - "329\n", - "330\n", - "331\n", - "332\n", - "333\n", - "334\n", - "335\n", - "336\n", - "337\n", - "338\n", - "339\n", - "340\n", - "341\n", - "342\n", - "343\n", - "344\n", - "345\n", - "346\n", - "347\n", - "348\n", - "349\n", - "350\n", - "351\n", - "352\n", - "353\n", - "354\n", - "355\n", - "356\n", - "357\n", - "358\n", - "359\n", - "360\n", - "361\n", - "362\n", - "363\n", - "364\n", - "365\n", - "366\n", - "367\n", - "368\n", - "369\n", - "370\n", - "371\n", - "372\n", - "373\n", - "374\n", - "375\n", - "376\n", - "377\n", - "378\n", - "379\n", - "380\n", - "381\n", - "382\n", - "383\n", - "384\n", - "385\n", - "386\n", - "387\n", - "388\n", - "389\n", - "390\n", - "391\n", - "392\n", - "393\n", - "394\n", - "395\n", - "396\n", - "397\n", - "398\n", - "399\n", - "400\n", - "401\n", - "402\n", - "403\n", - "404\n", - "405\n", - "406\n", - "407\n", - "408\n", - "409\n", - "410\n", - "411\n", - "412\n", - "413\n", - "414\n", - "415\n", - "416\n", - "417\n", - "418\n", - "419\n", - "420\n", - "421\n", - "422\n", - "423\n", - "424\n", - "425\n", - "426\n", - "427\n", - "428\n", - "429\n", - "430\n", - "431\n", - "432\n", - "433\n", - "434\n", - "435\n", - "436\n", - "437\n", - "438\n", - "439\n", - "440\n", - "441\n", - "442\n", - "443\n", - "444\n", - "445\n", - "446\n", - "447\n", - "448\n", - "449\n", - "450\n", - "451\n", - "452\n", - "453\n", - "454\n", - "455\n", - "456\n", - "457\n", - "458\n", - "459\n", - "460\n", - "461\n", - "462\n", - "463\n", - "464\n", - "465\n", - "466\n", - "467\n", - "468\n", - "469\n", - "470\n", - "471\n", - "472\n", - "473\n", - "474\n", - "475\n", - "476\n", - "477\n", - "478\n", - "479\n", - "480\n", - "481\n", - "482\n", - "483\n", - "484\n", - "485\n", - "486\n", - "487\n", - "488\n", - "489\n", - "490\n", - "491\n", - "492\n", - "493\n", - "494\n", - "495\n", - "496\n", - "497\n", - "498\n", - "499\n", - "500\n", - "501\n", - "502\n", - "503\n", - "504\n", - "505\n", - "506\n", - "507\n", - "508\n", - "509\n", - "510\n", - "511\n", - "512\n", - "513\n", - "514\n", - "515\n", - "516\n", - "517\n", - "518\n", - "519\n", - "520\n", - "521\n", - "522\n", - "523\n", - "524\n", - "525\n", - "526\n", - "527\n", - "528\n", - "529\n", - "530\n", - "531\n", - "532\n", - "533\n", - "534\n", - "535\n", - "536\n", - "537\n", - "538\n", - "539\n", - "540\n", - "541\n", - "542\n", - "543\n", - "544\n", - "545\n", - "546\n", - "547\n", - "548\n", - "549\n", - "550\n", - "551\n", - "552\n", - "553\n", - "554\n", - "555\n", - "556\n", - "557\n", - "558\n", - "559\n", - "560\n", - "561\n", - "562\n", - "563\n", - "564\n", - "565\n", - "566\n", - "567\n", - "568\n", - "569\n", - "570\n", - "571\n", - "572\n", - "573\n", - "574\n", - "575\n", - "576\n", - "577\n", - "578\n", - "579\n", - "580\n", - "581\n", - "582\n", - "583\n", - "584\n", - "585\n", - "586\n", - "587\n", - "588\n", - "589\n", - "590\n", - "591\n", - "592\n", - "593\n", - "594\n", - "595\n", - "596\n", - "597\n", - "598\n", - "599\n", - "600\n", - "601\n", - "602\n", - "603\n", - "604\n", - "605\n", - "606\n", - "607\n", - "608\n", - "609\n", - "610\n", - "611\n", - "612\n", - "613\n", - "614\n", - "615\n", - "616\n", - "617\n", - "618\n", - "619\n", - "620\n", - "621\n", - "622\n", - "623\n", - "624\n", - "625\n", - "626\n", - "627\n", - "628\n", - "629\n", - "630\n", - "631\n", - "632\n", - "633\n", - "634\n", - "635\n", - "636\n", - "637\n", - "638\n", - "639\n", - "640\n", - "641\n", - "642\n", - "643\n", - "644\n", - "645\n", - "646\n", - "647\n", - "648\n", - "649\n", - "650\n", - "651\n", - "652\n", - "653\n", - "654\n", - "655\n", - "656\n", - "657\n", - "658\n", - "659\n", - "660\n", - "661\n", - "662\n", - "663\n", - "664\n", - "665\n", - "666\n", - "667\n", - "668\n", - "669\n", - "670\n", - "671\n", - "672\n", - "673\n", - "674\n", - "675\n", - "676\n", - "677\n", - "678\n", - "679\n", - "680\n", - "681\n", - "682\n", - "683\n", - "684\n", - "685\n", - "686\n", - "687\n", - "688\n", - "689\n", - "690\n", - "691\n", - "692\n", - "693\n", - "694\n", - "695\n", - "696\n", - "697\n", - "698\n", - "699\n", - "700\n", - "701\n", - "702\n", - "703\n", - "704\n", - "705\n", - "706\n", - "707\n", - "708\n", - "709\n", - "710\n", - "711\n", - "712\n", - "713\n", - "714\n", - "715\n", - "716\n", - "717\n", - "718\n", - "719\n", - "720\n", - "721\n", - "722\n", - "723\n", - "724\n", - "725\n", - "726\n", - "727\n", - "728\n", - "729\n", - "730\n", - "731\n", - "732\n", - "733\n", - "734\n", - "735\n", - "736\n", - "737\n", - "738\n", - "739\n", - "740\n", - "741\n", - "742\n", - "743\n", - "744\n", - "745\n", - "746\n", - "747\n", - "748\n", - "749\n", - "750\n", - "751\n", - "752\n", - "753\n", - "754\n", - "755\n", - "756\n", - "757\n", - "758\n", - "759\n", - "760\n", - "761\n", - "762\n", - "763\n", - "764\n", - "765\n", - "766\n", - "767\n", - "768\n", - "769\n", - "770\n", - "771\n", - "772\n", - "773\n", - "774\n", - "775\n", - "776\n", - "777\n", - "778\n", - "779\n", - "780\n", - "781\n", - "782\n", - "783\n", - "784\n", - "785\n", - "786\n", - "787\n", - "788\n", - "789\n", - "790\n", - "791\n", - "792\n", - "793\n", - "794\n", - "795\n", - "796\n", - "797\n", - "798\n", - "799\n", - "800\n", - "801\n", - "802\n", - "803\n", - "804\n", - "805\n", - "806\n", - "807\n", - "808\n", - "809\n", - "810\n", - "811\n", - "812\n", - "813\n", - "814\n", - "815\n", - "816\n", - "817\n", - "818\n", - "819\n", - "820\n", - "821\n", - "822\n", - "823\n", - "824\n", - "825\n", - "826\n", - "827\n", - "828\n", - "829\n", - "830\n", - "831\n", - "832\n", - "833\n", - "834\n", - "835\n", - "836\n", - "837\n", - "838\n", - "839\n", - "840\n", - "841\n", - "842\n", - "843\n", - "844\n", - "845\n", - "846\n", - "847\n", - "848\n", - "849\n", - "850\n", - "851\n", - "852\n", - "853\n", - "854\n", - "855\n", - "856\n", - "857\n", - "858\n", - "859\n", - "860\n", - "861\n", - "862\n", - "863\n", - "864\n", - "865\n", - "866\n", - "867\n", - "868\n", - "869\n", - "870\n", - "871\n", - "872\n", - "873\n", - "874\n", - "875\n", - "876\n", - "877\n", - "878\n", - "879\n", - "880\n", - "881\n", - "882\n", - "883\n", - "884\n", - "885\n", - "886\n", - "887\n", - "888\n", - "889\n", - "890\n", - "891\n", - "892\n", - "893\n", - "894\n", - "895\n", - "896\n", - "897\n", - "898\n", - "899\n", - "900\n", - "901\n", - "902\n", - "903\n", - "904\n", - "905\n", - "906\n", - "907\n", - "908\n", - "909\n", - "910\n", - "911\n", - "912\n", - "913\n", - "914\n", - "915\n", - "916\n", - "917\n", - "918\n", - "919\n", - "920\n", - "921\n", - "922\n", - "923\n", - "924\n", - "925\n", - "926\n", - "927\n", - "928\n", - "929\n", - "930\n", - "931\n", - "932\n", - "933\n", - "934\n", - "935\n", - "936\n", - "937\n", - "938\n", - "939\n", - "940\n", - "941\n", - "942\n", - "943\n", - "944\n", - "945\n", - "946\n", - "947\n", - "948\n", - "949\n", - "950\n", - "951\n", - "952\n", - "953\n", - "954\n", - "955\n", - "956\n", - "957\n", - "958\n", - "959\n", - "960\n", - "961\n", - "962\n", - "963\n", - "964\n", - "965\n", - "966\n", - "967\n", - "968\n", - "969\n", - "970\n", - "971\n", - "972\n", - "973\n", - "974\n", - "975\n", - "976\n", - "977\n", - "978\n", - "979\n", - "980\n", - "981\n", - "982\n", - "983\n", - "984\n", - "985\n", - "986\n", - "987\n", - "988\n", - "989\n", - "990\n", - "991\n", - "992\n", - "993\n", - "994\n", - "995\n", - "996\n", - "997\n", - "998\n", - "999\n", - "1000\n", - "1001\n", - "1002\n", - "1003\n", - "1004\n", - "1005\n", - "1006\n", - "1007\n", - "1008\n", - "1009\n", - "1010\n", - "1011\n", - "1012\n", - "1013\n", - "1014\n", - "1015\n", - "1016\n", - "1017\n", - "1018\n", - "1019\n", - "1020\n", - "1021\n", - "1022\n", - "1023\n", - "1024\n", - "1025\n", - "1026\n", - "1027\n", - "1028\n", - "1029\n", - "1030\n", - "1031\n", - "1032\n", - "1033\n", - "1034\n", - "1035\n", - "1036\n", - "1037\n", - "1038\n", - "1039\n", - "1040\n", - "1041\n", - "1042\n", - "1043\n", - "1044\n", - "1045\n", - "1046\n", - "1047\n", - "1048\n", - "1049\n", - "1050\n", - "1051\n", - "1052\n", - "1053\n", - "1054\n", - "1055\n", - "1056\n", - "1057\n", - "1058\n", - "1059\n", - "1060\n", - "1061\n", - "1062\n", - "1063\n", - "1064\n", - "1065\n", - "1066\n", - "1067\n", - "1068\n", - "1069\n", - "1070\n", - "1071\n", - "1072\n", - "1073\n", - "1074\n", - "1075\n", - "1076\n", - "1077\n", - "1078\n", - "1079\n", - "1080\n", - "1081\n", - "1082\n", - "1083\n", - "1084\n", - "1085\n", - "1086\n", - "1087\n", - "1088\n", - "1089\n", - "1090\n", - "1091\n", - "1092\n", - "1093\n", - "1094\n", - "1095\n", - "1096\n", - "1097\n", - "1098\n", - "1099\n", - "1100\n", - "1101\n", - "1102\n", - "1103\n", - "1104\n", - "1105\n", - "1106\n", - "1107\n", - "1108\n", - "1109\n", - "1110\n", - "1111\n", - "1112\n", - "1113\n", - "1114\n", - "1115\n", - "1116\n", - "1117\n", - "1118\n", - "1119\n", - "1120\n", - "1121\n", - "1122\n", - "1123\n", - "1124\n", - "1125\n", - "1126\n", - "1127\n", - "1128\n", - "1129\n", - "1130\n", - "1131\n", - "1132\n", - "1133\n", - "1134\n", - "1135\n", - "1136\n", - "1137\n", - "1138\n", - "1139\n", - "1140\n", - "1141\n", - "1142\n", - "1143\n", - "1144\n", - "1145\n", - "1146\n", - "1147\n", - "1148\n", - "1149\n", - "1150\n", - "1151\n", - "1152\n", - "1153\n", - "1154\n", - "1155\n", - "1156\n", - "1157\n", - "1158\n", - "1159\n", - "1160\n", - "1161\n", - "1162\n", - "1163\n", - "1164\n", - "1165\n", - "1166\n", - "1167\n", - "1168\n", - "1169\n", - "1170\n", - "1171\n", - "1172\n", - "1173\n", - "1174\n", - "1175\n", - "1176\n", - "1177\n", - "1178\n", - "1179\n", - "1180\n", - "1181\n", - "1182\n", - "1183\n", - "1184\n", - "1185\n", - "1186\n", - "1187\n", - "1188\n", - "1189\n", - "1190\n", - "1191\n", - "1192\n", - "1193\n", - "1194\n", - "1195\n", - "1196\n", - "1197\n", - "1198\n", - "1199\n", - "1200\n", - "1201\n", - "1202\n", - "1203\n", - "1204\n", - "1205\n", - "1206\n", - "1207\n", - "1208\n", - "1209\n", - "1210\n", - "1211\n", - "1212\n", - "1213\n", - "1214\n", - "1215\n", - "1216\n", - "1217\n", - "1218\n", - "1219\n", - "1220\n", - "1221\n", - "1222\n", - "1223\n", - "1224\n", - "1225\n", - "1226\n", - "1227\n", - "1228\n", - "1229\n", - "1230\n", - "1231\n", - "1232\n", - "1233\n", - "1234\n", - "1235\n", - "1236\n", - "1237\n", - "1238\n", - "1239\n", - "1240\n", - "1241\n", - "1242\n", - "1243\n", - "1244\n", - "1245\n", - "1246\n", - "1247\n", - "1248\n", - "1249\n" + "9\n" ] } ], @@ -1649,6 +415,765 @@ "len(backgrounds)" ] }, + { + "cell_type": "code", + "execution_count": 196, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Using cache found in /home/akhot2/.cache/torch/hub/ultralytics_yolov5_master\n", + "YOLOv5 🚀 2023-3-31 Python-3.9.12 torch-1.11.0 CUDA:0 (A100-SXM4-40GB, 40537MiB)\n", + "\n", + "Fusing layers... \n", + "Model summary: 212 layers, 20852934 parameters, 0 gradients, 47.9 GFLOPs\n", + "Adding AutoShape... \n" + ] + }, + { + "data": { + "text/plain": [ + "AutoShape(\n", + " (model): DetectMultiBackend(\n", + " (model): DetectionModel(\n", + " (model): Sequential(\n", + " (0): Conv(\n", + " (conv): Conv2d(3, 48, kernel_size=(6, 6), stride=(2, 2), padding=(2, 2))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (1): Conv(\n", + " (conv): Conv2d(48, 96, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (2): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(96, 48, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(96, 48, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(96, 96, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(48, 48, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(48, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (1): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(48, 48, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(48, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (3): Conv(\n", + " (conv): Conv2d(96, 192, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (4): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(192, 96, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(192, 96, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(96, 96, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(96, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (1): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(96, 96, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(96, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (2): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(96, 96, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(96, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (3): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(96, 96, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(96, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (5): Conv(\n", + " (conv): Conv2d(192, 384, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (6): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(384, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(384, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(384, 384, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (1): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (2): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (3): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (4): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (5): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (7): Conv(\n", + " (conv): Conv2d(384, 768, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (8): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(768, 384, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(768, 384, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(768, 768, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(384, 384, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(384, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (1): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(384, 384, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(384, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (9): SPPF(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(768, 384, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(1536, 768, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): MaxPool2d(kernel_size=5, stride=1, padding=2, dilation=1, ceil_mode=False)\n", + " )\n", + " (10): Conv(\n", + " (conv): Conv2d(768, 384, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (11): Upsample(scale_factor=2.0, mode=nearest)\n", + " (12): Concat()\n", + " (13): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(384, 384, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (1): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (14): Conv(\n", + " (conv): Conv2d(384, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (15): Upsample(scale_factor=2.0, mode=nearest)\n", + " (16): Concat()\n", + " (17): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(384, 96, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(384, 96, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(96, 96, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(96, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (1): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(96, 96, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(96, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (18): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (19): Concat()\n", + " (20): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(384, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(384, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(384, 384, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (1): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (21): Conv(\n", + " (conv): Conv2d(384, 384, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (22): Concat()\n", + " (23): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(768, 384, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(768, 384, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(768, 768, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(384, 384, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(384, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (1): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(384, 384, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(384, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (24): Detect(\n", + " (m): ModuleList(\n", + " (0): Conv2d(192, 18, kernel_size=(1, 1), stride=(1, 1))\n", + " (1): Conv2d(384, 18, kernel_size=(1, 1), stride=(1, 1))\n", + " (2): Conv2d(768, 18, kernel_size=(1, 1), stride=(1, 1))\n", + " )\n", + " )\n", + " )\n", + " )\n", + " )\n", + ")" + ] + }, + "execution_count": 196, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "model = torch.hub.load('ultralytics/yolov5', 'custom', '/raid/projects/akhot2/group-01-phys371-sp2023/yolov5_model/runs/train/20beetle_40-non_20dirt_bkg_overlap/weights/best.pt')\n", + "model.eval()" + ] + }, + { + "cell_type": "code", + "execution_count": 199, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "YOLOv5 <class 'models.common.Detections'> instance\n", + "image 1/1: 2746x1610 3 beetless\n", + "Speed: 125.2ms pre-process, 13.4ms inference, 1.1ms NMS per image at shape (1, 3, 640, 384)" + ] + }, + "execution_count": 199, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model('/raid/projects/akhot2/group-01-phys371-sp2023/crop/data/train/images/sim1.png')" + ] + }, + { + "cell_type": "code", + "execution_count": 153, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real18.jpg\n", + "(1744, 2778)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real16.jpg\n", + "(1894, 3155)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real7.jpg\n", + "(1837, 2978)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real8.jpg\n", + "(1680, 2791)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real10.jpg\n", + "(1880, 3101)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real13.jpg\n", + "(1572, 2582)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real15.jpg\n", + "(1486, 2422)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real6.jpg\n", + "(1635, 2699)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/F28_3AUGUST2022_cropped.jpg\n", + "(1850, 2765)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/bg.png\n", + "(2114, 3236)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real17.jpg\n", + "(1769, 3095)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real1.jpg\n", + "(1751, 2631)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real20.jpg\n", + "(1521, 2306)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real4.jpg\n", + "(1640, 2289)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real3.jpg\n", + "(1610, 2746)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real19.jpg\n", + "(1662, 2767)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real9.jpg\n", + "(1627, 2155)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real14.jpg\n", + "(1548, 2187)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real5.jpg\n", + "(1940, 2713)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real12.jpg\n", + "(1494, 2695)\n", + "/raid/projects/akhot2/group-01-phys371-sp2023/crop/cropped_imgs/real2.jpg\n", + "(1940, 2713)\n" + ] + } + ], + "source": [ + "width = []\n", + "height = []\n", + "for file in glob.glob('/raid/projects/akhot2/group-01-phys371-sp2023/crop/data/train/sim0.png'):\n", + " print(file)\n", + " n_b0 = Image.open(file)\n", + " print(n_b0.size)\n", + " w, h = n_b0.size\n", + " width.append(w)\n", + " height.append(h)\n", + " #f = model(file)\n", + " #print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "78.57894736842105" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.mean(width)" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "92.47368421052632" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.mean(height)" + ] + }, + { + "cell_type": "code", + "execution_count": 154, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1723.5238095238096" + ] + }, + "execution_count": 154, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.mean(width)" + ] + }, + { + "cell_type": "code", + "execution_count": 155, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2704.9523809523807" + ] + }, + "execution_count": 155, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.mean(height)" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "94.5" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "width[8]*.7" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "54.599999999999994" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "height[8]*.7" + ] + }, + { + "cell_type": "code", + "execution_count": 156, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1744,\n", + " 1894,\n", + " 1837,\n", + " 1680,\n", + " 1880,\n", + " 1572,\n", + " 1486,\n", + " 1635,\n", + " 1850,\n", + " 2114,\n", + " 1769,\n", + " 1751,\n", + " 1521,\n", + " 1640,\n", + " 1610,\n", + " 1662,\n", + " 1627,\n", + " 1548,\n", + " 1940,\n", + " 1494,\n", + " 1940]" + ] + }, + "execution_count": 156, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "width" + ] + }, + { + "cell_type": "code", + "execution_count": 166, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "51.44444444444444\n", + "41.15555555555556\n", + "58.425925925925924\n", + "46.74074074074074\n", + "55.148148148148145\n", + "44.11851851851852\n", + "51.68518518518518\n", + "41.34814814814815\n", + "57.425925925925924\n", + "45.94074074074074\n", + "47.81481481481482\n", + "38.25185185185185\n", + "44.851851851851855\n", + "35.88148148148148\n", + "49.98148148148148\n", + "39.98518518518519\n", + "51.2037037037037\n", + "40.96296296296296\n", + "59.925925925925924\n", + "47.94074074074074\n", + "57.31481481481482\n", + "45.851851851851855\n", + "48.72222222222222\n", + "38.977777777777774\n", + "42.7037037037037\n", + "34.162962962962965\n", + "42.388888888888886\n", + "33.91111111111111\n", + "50.851851851851855\n", + "40.681481481481484\n", + "51.24074074074074\n", + "40.992592592592594\n", + "39.907407407407405\n", + "31.925925925925927\n", + "40.5\n", + "32.4\n", + "50.24074074074074\n", + "40.19259259259259\n", + "49.907407407407405\n", + "39.925925925925924\n", + "50.24074074074074\n", + "40.19259259259259\n" + ] + } + ], + "source": [ + "for i in height:\n", + " print((i/(6*9)))\n", + " print((i/(7.5*9)))" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/crop/need_nonbeetles/B10_15August2022_cropped.jpg b/crop/need_nonbeetles/B10_15August2022_cropped.jpg deleted file mode 100644 index c33b59b3553b1343c4593b876445f98602817403..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/B10_15August2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/B12_15August2022_cropped.jpg b/crop/need_nonbeetles/B12_15August2022_cropped.jpg deleted file mode 100644 index a57fb883076e51ca53da14f8af4db1bafd950209..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/B12_15August2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/B18b_25August2022_cropped.jpg b/crop/need_nonbeetles/B18b_25August2022_cropped.jpg deleted file mode 100644 index 121633a2ba7fdcfaacd388dc0bdeb6e77fcd28f4..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/B18b_25August2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/B26_25August2022_cropped.jpg b/crop/need_nonbeetles/B26_25August2022_cropped.jpg deleted file mode 100644 index 0897b5604eab9149f9a21d61493490ba2e757af4..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/B26_25August2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/B2_25August2022_cropped.jpg b/crop/need_nonbeetles/B2_25August2022_cropped.jpg deleted file mode 100644 index 6638b792e3ca9bf7fb4bcf26468f50b53b3c3611..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/B2_25August2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/B2_3AUGUST2022_cropped.jpg b/crop/need_nonbeetles/B2_3AUGUST2022_cropped.jpg deleted file mode 100644 index fa3a98b63430a929c885d3039d3de2e6c60e2061..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/B2_3AUGUST2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/B30_25August2022_cropped.jpg b/crop/need_nonbeetles/B30_25August2022_cropped.jpg deleted file mode 100644 index 41fa371eb8df0d074425a88d51cb8dae04ca4016..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/B30_25August2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/F14_3AUGUST2022_cropped.jpg b/crop/need_nonbeetles/F14_3AUGUST2022_cropped.jpg deleted file mode 100644 index b27e9ec13f9b602f9e94d5866b8ef5e82460b096..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/F14_3AUGUST2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/F18_3AUGUST2022_cropped.jpg b/crop/need_nonbeetles/F18_3AUGUST2022_cropped.jpg deleted file mode 100644 index 1df9549bbf5bf0f8df579fa5bb8dbaa795fd6750..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/F18_3AUGUST2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/F26_26JUL2022_cropped.jpg b/crop/need_nonbeetles/F26_26JUL2022_cropped.jpg deleted file mode 100644 index 38c2923e536dfb24729052be7f0faba970fbafb2..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/F26_26JUL2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/F2_26JUL2022_cropped.jpg b/crop/need_nonbeetles/F2_26JUL2022_cropped.jpg deleted file mode 100644 index 1f2b9074ed390ccb5a3c36dea7c8b30eb3389086..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/F2_26JUL2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/F2_3AUGUST2022_cropped.jpg b/crop/need_nonbeetles/F2_3AUGUST2022_cropped.jpg deleted file mode 100644 index 02b77b3369ae08c307da709465b16a97ca271e2b..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/F2_3AUGUST2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/F4_3AUGUST2022_cropped.jpg b/crop/need_nonbeetles/F4_3AUGUST2022_cropped.jpg deleted file mode 100644 index 41f2b62aa3abc619fd0172a96d4df32d7c2d1e25..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/F4_3AUGUST2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/F6_3AUGUST2022_cropped.jpg b/crop/need_nonbeetles/F6_3AUGUST2022_cropped.jpg deleted file mode 100644 index 25261b2cf83708d10cf5e3ff9c71925a33bb1aea..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/F6_3AUGUST2022_cropped.jpg and /dev/null differ diff --git a/crop/need_nonbeetles/M10_19July2022.jpg b/crop/need_nonbeetles/M10_19July2022.jpg deleted file mode 100644 index 8626878310237ded77be75f92d3a52621fb6e3ec..0000000000000000000000000000000000000000 Binary files a/crop/need_nonbeetles/M10_19July2022.jpg and /dev/null differ diff --git a/training/.ipynb_checkpoints/PreProcessor-checkpoint.ipynb b/training/.ipynb_checkpoints/PreProcessor-checkpoint.ipynb deleted file mode 100644 index 0f66bcf8262fa92c2122929ccf96f30c5a92c406..0000000000000000000000000000000000000000 --- a/training/.ipynb_checkpoints/PreProcessor-checkpoint.ipynb +++ /dev/null @@ -1,908 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "ff555f6b", - "metadata": {}, - "outputs": [], - "source": [ - "import glob\n", - "from tqdm import tqdm\n", - "import pandas as pd \n", - "import torch\n", - "from PIL import Image\n", - "import torchvision.transforms as transforms\n", - "import matplotlib.pyplot as plt\n", - "import pillow_heif\n", - "import os\n", - "import pickle" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "fd6db132", - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/raid/projects/akhot2/conda/envs/akhot2/lib/python3.9/site-packages/openpyxl/worksheet/header_footer.py:48: UserWarning: Cannot parse header or footer so it will be ignored\n", - " warn(\"\"\"Cannot parse header or footer so it will be ignored\"\"\")\n" - ] - }, - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>Grand Acc #</th>\n", - " <th>Weekly Acc#</th>\n", - " <th>Sample collection period</th>\n", - " <th>Sticky trap pair (rep)</th>\n", - " <th>2022 Julian Date</th>\n", - " <th>Month</th>\n", - " <th>2022 Set up Date</th>\n", - " <th>2022 Data Collect. Date</th>\n", - " <th>Coll. intrvl (d)</th>\n", - " <th>Coll. hour</th>\n", - " <th>...</th>\n", - " <th>NCR/trap /day</th>\n", - " <th>WCR/trap /day</th>\n", - " <th>Total CRW /trap /day</th>\n", - " <th>NCR/trap top /day</th>\n", - " <th>WCR/trap top/day</th>\n", - " <th>Total CRW /trap top/day</th>\n", - " <th>Proportion NCR on top</th>\n", - " <th>Proportion WCR on top</th>\n", - " <th>Proportion All CRW on top</th>\n", - " <th>Notes</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>2</td>\n", - " <td>2</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>2022-07-08</td>\n", - " <td>2022-07-19</td>\n", - " <td>11.0</td>\n", - " <td>11.35</td>\n", - " <td>...</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>4</td>\n", - " <td>4</td>\n", - " <td>1</td>\n", - " <td>2</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>2022-07-08</td>\n", - " <td>2022-07-19</td>\n", - " <td>11.0</td>\n", - " <td>11.35</td>\n", - " <td>...</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>6</td>\n", - " <td>6</td>\n", - " <td>1</td>\n", - " <td>3</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>2022-07-08</td>\n", - " <td>2022-07-19</td>\n", - " <td>11.0</td>\n", - " <td>11.35</td>\n", - " <td>...</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>8</td>\n", - " <td>8</td>\n", - " <td>1</td>\n", - " <td>4</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>2022-07-08</td>\n", - " <td>2022-07-19</td>\n", - " <td>11.0</td>\n", - " <td>11.35</td>\n", - " <td>...</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>10</td>\n", - " <td>10</td>\n", - " <td>1</td>\n", - " <td>5</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>2022-07-08</td>\n", - " <td>2022-07-19</td>\n", - " <td>11.0</td>\n", - " <td>11.35</td>\n", - " <td>...</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "<p>5 rows × 43 columns</p>\n", - "</div>" - ], - "text/plain": [ - " Grand Acc # Weekly Acc# Sample collection period Sticky trap pair (rep) \\\n", - "0 2 2 1 1 \n", - "1 4 4 1 2 \n", - "2 6 6 1 3 \n", - "3 8 8 1 4 \n", - "4 10 10 1 5 \n", - "\n", - " 2022 Julian Date Month 2022 Set up Date 2022 Data Collect. Date \\\n", - "0 NaN NaN 2022-07-08 2022-07-19 \n", - "1 NaN NaN 2022-07-08 2022-07-19 \n", - "2 NaN NaN 2022-07-08 2022-07-19 \n", - "3 NaN NaN 2022-07-08 2022-07-19 \n", - "4 NaN NaN 2022-07-08 2022-07-19 \n", - "\n", - " Coll. intrvl (d) Coll. hour ... NCR/trap /day WCR/trap /day \\\n", - "0 11.0 11.35 ... 0.0 0.0 \n", - "1 11.0 11.35 ... 0.0 0.0 \n", - "2 11.0 11.35 ... 0.0 0.0 \n", - "3 11.0 11.35 ... 0.0 0.0 \n", - "4 11.0 11.35 ... 0.0 0.0 \n", - "\n", - " Total CRW /trap /day NCR/trap top /day WCR/trap top/day \\\n", - "0 0.0 0.0 0.0 \n", - "1 0.0 0.0 0.0 \n", - "2 0.0 0.0 0.0 \n", - "3 0.0 0.0 0.0 \n", - "4 0.0 0.0 0.0 \n", - "\n", - " Total CRW /trap top/day Proportion NCR on top Proportion WCR on top \\\n", - "0 0.0 NaN NaN \n", - "1 0.0 NaN NaN \n", - "2 0.0 NaN NaN \n", - "3 0.0 NaN NaN \n", - "4 0.0 NaN NaN \n", - "\n", - " Proportion All CRW on top Notes \n", - "0 NaN NaN \n", - "1 NaN NaN \n", - "2 NaN NaN \n", - "3 NaN NaN \n", - "4 NaN NaN \n", - "\n", - "[5 rows x 43 columns]" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "labels_path = \"../data/trap_labels.xlsx\"\n", - "df = pd.read_excel(labels_path)\n", - "df.head()" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "7097a875", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Index(['Grand Acc #', 'Weekly Acc#', 'Sample collection period',\n", - " 'Sticky trap pair (rep)', '2022 Julian Date', 'Month',\n", - " '2022 Set up Date', '2022 Data Collect. Date', 'Coll. intrvl (d)',\n", - " 'Coll. hour', 'Trap visitor', 'Drone pilot', 'On farm location',\n", - " 'Site Abrv.', 'trap angle', 'trap orient'n', 'Trap #',\n", - " 'Sticky Trap Name', 'T-top side NCR', 'bottom side NCR',\n", - " 'T-top side WCR', 'bottom side WCR', 'WCR mal', 'WCR fem',\n", - " 'T-top side \"other\"', 'Bottom side \"other\"', 'T-top side total CRW',\n", - " 'bottom side total CRW', 'Trap Total NCR', 'Trap Total WCR',\n", - " 'Trap Total CRW', 'Proportion NCR in total CRW',\n", - " 'Proportion WCR in total CRW', 'NCR/trap /day', 'WCR/trap /day',\n", - " 'Total CRW /trap /day', 'NCR/trap top /day', 'WCR/trap top/day',\n", - " 'Total CRW /trap top/day', 'Proportion NCR on top',\n", - " 'Proportion WCR on top', 'Proportion All CRW on top', 'Notes'],\n", - " dtype='object')" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.columns" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "24d3874e", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>trap orient'n</th>\n", - " <th>2022 Data Collect. Date</th>\n", - " <th>Sticky Trap Name</th>\n", - " <th>T-top side WCR</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>Angled</td>\n", - " <td>2022-07-19</td>\n", - " <td>U2</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>Angled</td>\n", - " <td>2022-07-19</td>\n", - " <td>U4</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>Angled</td>\n", - " <td>2022-07-19</td>\n", - " <td>U6</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>Angled</td>\n", - " <td>2022-07-19</td>\n", - " <td>U8</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>Angled</td>\n", - " <td>2022-07-19</td>\n", - " <td>U10</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>...</th>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " </tr>\n", - " <tr>\n", - " <th>603</th>\n", - " <td>Angled</td>\n", - " <td>NaT</td>\n", - " <td>M24</td>\n", - " <td>nan</td>\n", - " </tr>\n", - " <tr>\n", - " <th>604</th>\n", - " <td>Angled</td>\n", - " <td>NaT</td>\n", - " <td>M26</td>\n", - " <td>nan</td>\n", - " </tr>\n", - " <tr>\n", - " <th>605</th>\n", - " <td>Angled</td>\n", - " <td>NaT</td>\n", - " <td>M28</td>\n", - " <td>nan</td>\n", - " </tr>\n", - " <tr>\n", - " <th>606</th>\n", - " <td>Angled</td>\n", - " <td>NaT</td>\n", - " <td>M30</td>\n", - " <td>nan</td>\n", - " </tr>\n", - " <tr>\n", - " <th>607</th>\n", - " <td>Angled</td>\n", - " <td>NaT</td>\n", - " <td>M32</td>\n", - " <td>nan</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "<p>320 rows × 4 columns</p>\n", - "</div>" - ], - "text/plain": [ - " trap orient'n 2022 Data Collect. Date Sticky Trap Name T-top side WCR\n", - "0 Angled 2022-07-19 U2 0\n", - "1 Angled 2022-07-19 U4 0\n", - "2 Angled 2022-07-19 U6 0\n", - "3 Angled 2022-07-19 U8 0\n", - "4 Angled 2022-07-19 U10 0\n", - ".. ... ... ... ...\n", - "603 Angled NaT M24 nan\n", - "604 Angled NaT M26 nan\n", - "605 Angled NaT M28 nan\n", - "606 Angled NaT M30 nan\n", - "607 Angled NaT M32 nan\n", - "\n", - "[320 rows x 4 columns]" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df_angled = df[df[\"trap orient'n\"] == \"Angled \"].astype(str)\n", - "df_angled[[\"trap orient'n\", \"2022 Data Collect. Date\", \"Sticky Trap Name\", \"T-top side WCR\"]]" - ] - }, - { - "cell_type": "code", - "execution_count": 71, - "id": "0ccf1183", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "B8_15August2022.jpg\n", - "B12_15August2022.jpg\n", - "B26_15August2022.jpg\n", - "B22_15August2022.jpg\n", - "B4_15August2022.jpg\n", - "B20_15August2022.jpg\n", - "B32_15August2022.jpg\n", - "B16_15August2022.jpg\n", - "B18_15August2022.jpg\n", - "B28_15August2022.jpg\n", - "B14_15August2022.jpg\n", - "B24_15August2022.jpg\n", - "B10_15August2022.jpg\n", - "B2_15August2022.jpg\n", - "B6_15August2022.jpg\n", - "B28_25August2022.jpg\n", - "B26_25August2022.jpg\n", - "B24_25August2022.jpg\n", - "B16_25August2022.HEIC\n", - "B12_25August2022.HEIC\n", - "B2_25August2022.HEIC\n", - "B20_25August2022.jpg\n", - "B8_25August2022.HEIC\n", - "B18_25August2022.jpg\n", - "B18c_25August2022.jpg\n", - "B32_25August2022.jpg\n", - "B4_25August2022.HEIC\n", - "B22_25August2022.jpg\n", - "B6_25August2022.HEIC\n", - "B10_25August2022.HEIC\n", - "B30_25August2022.jpg\n", - "B14_25August2022.HEIC\n", - "B18b_25August2022.jpg\n", - "B30b_25August2022.jpg\n", - "B14_20July2022.jpg\n", - "B8_20July2022.jpg\n", - "B32_20July2022.jpg\n", - "B28b_20July2022.jpg\n", - "B26b_20July2022.jpg\n", - "B32b_20July2022.jpg\n", - "B16_20JULY2022.jpg\n", - "B26_20July2022.jpg\n", - "B30_20July2022.jpg\n", - "B2_20July2022.jpg\n", - "B4_20July2022.jpg\n", - "B10_20July2022.jpg\n", - "B28_20July2022.jpg\n", - "B12_20July2022.jpg\n", - "B6_20July2022.jpg\n", - "B2_3AUGUST2022.HEIC\n", - "B18_3AUGUST2022.jpeg\n", - "B20_3AUGUST2022.jpeg\n", - "B4_3AUGUST2022.HEIC\n", - "B10_3AUGUST2022.HEIC\n", - "B26_3AUGUST2022.jpeg\n", - "B8_3AUGUST2022.HEIC\n", - "B28_3AUGUST2022.jpeg\n", - "B22_3AUGUST2022.jpeg\n", - "B14_3AUGUST2022.HEIC\n", - "B16_3AUGUST2022.HEIC\n", - "B24_3AUGUST2022.jpeg\n", - "B12_3AUGUST2022.HEIC\n", - "B6_3AUGUST2022.HEIC\n", - "B8_26JUL2022.jpg\n", - "B14_26JUL2022.jpg\n", - "B6_26JUL2022.jpg\n", - "B2_26JUL2022.jpg\n", - "B4_26JUL2022.jpg\n", - "B10_26JUL2022.jpg\n", - "B16_26JUL2022.jpg\n", - "B12_26JUL2022jpg.jpg\n", - "F2_3AUGUST2022.jpg\n", - "F28_3AUGUST2022.HEIC\n", - "F18_3AUGUST2022.HEIC\n", - "F10_3AUGUST2022.jpg\n", - "F16_3AUGUST2022.jpg\n", - "F6_3AUGUST2022.jpg\n", - "F12_3AUGUST2022jpg.jpg\n", - "F26_3AUGUST2022.HEIC\n", - "F4_3AUGUST2022.jpg\n", - "F8_3AUGUST2022.jpg\n", - "F20_3AUGUST2022.HEIC\n", - "F30_3AUGUST2022.HEIC\n", - "F22_3AUGUST2022.HEIC\n", - "F32_3AUGUST2022.HEIC\n", - "F14_3AUGUST2022.jpg\n", - "F24_3AUGUST2022.HEIC\n", - "F28_25August2022.HEIC\n", - "F2b_25August2022.heic\n", - "F16b_25August2022.jpg\n", - "F26_25August2022.HEIC\n", - "F32_25August2022.HEIC\n", - "F16_25August2022.jpg\n", - "F12_25August2022.jpg\n", - "F30_25August2022.HEIC\n", - "F2_25August2022.jpg\n", - "F24_25August2022.HEIC\n", - "F20_25August2022.HEIC\n", - "F14_25August2022.jpg\n", - "F22_25August2022.HEIC\n", - "F18_25August2022.HEIC\n", - "F14b_25August2022.jpg\n", - "F14_20July2022.jpg\n", - "F32_20July2022.jpg\n", - "F8_20July2022.jpg\n", - "F12_20July2022.jpg\n", - "F28_20July2022.jpg\n", - "F30_20July2022.jpg\n", - "F18_20July2022.jpg\n", - "F20_20July2022.jpg\n", - "F2_20July2022.jpg\n", - "F26_20July2022.jpg\n", - "F22_20July2022.jpg\n", - "F6b_20July2022.jpg\n", - "F6_20July2022.jpg\n", - "F16_20July2022.jpg\n", - "F24_20July2022.jpg\n", - "F10_20July2022.jpg\n", - "F20_26JUL2022.HEIC\n", - "F26_26JUL2022.HEIC\n", - "F8_26JUL2022.jpg\n", - "F28_26JUL2022.HEIC\n", - "F30_26JUL2022.HEIC\n", - "F2_26JUL2022.jpg\n", - "F24_26JUL2022.HEIC\n", - "F18_26JUL2022.HEIC\n", - "F10_26JUL2022.jpg\n", - "F32_26JUL2022.HEIC\n", - "F22_26JUL2022.HEIC\n", - "M16_19July2022.jpg\n", - "M10_19July2022.jpg\n", - "M2_19July2022.jpg\n", - "M14_19July2022.jpg\n", - "M12_19July2022.jpg\n", - "M6_19July2022.jpg\n", - "M4_19July2022.jpg\n", - "M8_19July2022.jpg\n", - "M20_4AUGUST2022..jpg\n", - "M18_4AUGUST2022.jpg\n", - "M2_4AUGUST2022.HEIC\n", - "M22_4AUGUST2022.jpg\n", - "M30_4AUGUST2022..jpg\n", - "M8_4AUGUST2022.HEIC\n", - "M16_4AUGUST2022.HEIC\n", - "M10_4AUGUST2022.HEIC\n", - "M6_4AUGUST2022.HEIC\n", - "M12_4AUGUST2022.HEIC\n", - "M26_4AUGUST2022.jpg\n", - "M28_4AUGUST2022..jpg\n", - "M32_4AUGUST2022..jpg\n", - "M24_4AUGUST2022..jpg\n", - "M14_4AUGUST2022.HEIC\n", - "M32_17AUGUST2022.jpg\n", - "M24_17AUGUST2022.jpg\n", - "M30_17AUGUST2022.jpg\n", - "M10_17AUGUST2022.HEIC\n", - "M22_17AUGUST2022.jpg\n", - "M2_17AUGUST2022.HEIC\n", - "M16_17AUGUST2022.HEIC\n", - "M26_17AUGUST2022.jpg\n", - "M14_17AUGUST2022.HEIC\n", - "M12_17AUGUST2022.HEIC\n", - "M18_17AUGUST2022.jpg\n", - "M28_17AUGUST2022.jpg\n", - "M6_17AUGUST2022.HEIC\n", - "M4_17AUGUST2022.HEIC\n", - "M8_17AUGUST2022.HEIC\n", - "M20_17AUGUST2022.jpg\n", - "M12_27JULY2022.jpg\n", - "M8_27JULY2022.jpg\n", - "M26_27JULY2022.jpeg\n", - "M16_27JULY2022.jpg\n", - "M32_27JULY2022.jpeg\n", - "M30_27JULY2022.jpeg\n", - "M10_27JULY2022.jpg\n", - "M4_27JULY2022.jpg\n", - "M14_27JULY2022.jpg\n", - "M20_27JULY2022.jpeg\n", - "M28_27JULY2022.jpeg\n", - "M6_27JULY2022.jpg\n", - "M22_27JULY2022.jpeg\n", - "M24_27JULY2022.jpeg\n", - "M2_27JULY2022.jpg\n", - "U30_19JULY2022.jpg\n", - "U2_19JULY2022.HEIC\n", - "U10_19JULY2022.HEIC\n", - "U20_19JULY2022jpg.jpg\n", - "U22_19JULY2022.jpg\n", - "U16_19JULY2022.HEIC\n", - "U24_19JULY2022.jpg\n", - "U8_19JULY2022.HEIC\n", - "U14_19JULY2022.HEIC\n", - "U18_19JULY2022.jpg\n", - "U4_19JULY2022.HEIC\n", - "U12_19JULY2022.HEIC\n", - "U26_19JULY2022.jpg\n", - "U6_19JULY2022.HEIC\n", - "U32_19JULY2022.jpg\n", - "U28_19JULY2022.jpg\n", - "U26_5AUGUST2022.jpg\n", - "U32_5AUGUST2022jpg.jpg\n", - "U10_5August2022(4979).HEIC\n", - "U8_5August2022(4980).HEIC\n", - "U6_5August2022(4981).HEIC\n", - "U16_5August2022(4977).HEIC\n", - "U2_5August2022(4983).HEIC\n", - "U24_5AUGUST2022.jpg\n", - "U20_5AUGUST2022.jpg\n", - "U4_5August2022(4982).HEIC\n", - "U12_5August2022(4978).HEIC\n", - "U18_5AUGUST2022.jpg\n", - "U28_5AUGUST2022.jpg\n", - "U22_5AUGUST2022.jpg\n", - "U30_5AUGUST2022.jpg\n", - "U26_27JULY2022.jpg\n", - "U20_27JULY2022.jpg\n", - "U2_27JULY2022.HEIC\n", - "U16_27JULY2022.HEIC\n", - "U10_27JULY2022.HEIC\n", - "U24_27JULY2022.jpg\n", - "U6_27JULY2022.HEIC\n", - "U12_27JULY2022.HEIC\n", - "U8_27JULY2022.HEIC\n", - "U4_27JULY2022.HEIC\n", - "U28_27JULY2022.jpg\n", - "U32_27JULY2022.jpg\n", - "U30_27JULY2022.jpg\n", - "U22_27JULY2022jpg.jpg\n", - "U18_27JULY2022.jpg\n", - "U14_27JULY2022.HEIC\n", - "U4_10AUGUST2022.HEIC\n", - "U22_10AUGUST2022.jpg\n", - "U26_10AUGUST2022.jpg\n", - "U24_10AUGUST2022.jpg\n", - "U28_10AUGUST2022.jpg\n", - "U30_10AUGUST2022.jpg\n", - "U10_10AUGUST2022.HEIC\n", - "U32_10AUGUST2022.jpg\n", - "U18_10AUGUST2022.jpg\n", - "U20_10AUGUST2022.jpg\n", - "U16_10AUGUST2022.HEIC\n", - "U14_10AUGUST2022.HEIC\n", - "U2_10AUGUST2022.HEIC\n", - "U8_10AUGUST2022.HEIC\n", - "U12_10AUGUST2022.HEIC\n", - "U6_10AUGUST2022.HEIC\n", - "U16_23August2022.HEIC\n", - "U12_23August2022.HEIC\n", - "U26_23August2022.jpg\n", - "U20_23August2022.jpg\n", - "U10_23August2022.HEIC\n", - "U6_23August2022.HEIC\n", - "U4_23August2022.HEIC\n", - "U2_23August2022.HEIC\n", - "U28_23August2022.jpg\n", - "U22_23August2022.jpg\n", - "U14_23August2022.HEIC\n", - "U18_23August2022.HEIC\n", - "U18_23August2022.jpg\n", - "U24_23August2022.jpg\n", - "U28b_23August2022.jpg\n", - "U30_23August2022.jpg\n", - "U32_23August2022.jpg\n" - ] - } - ], - "source": [ - "folders = [\"buchhloz\", \"faivre\", \"moore\", \"underwood\"]\n", - "\n", - "\n", - "images = []\n", - "total_beetles = 0\n", - "for folder_name in folders:\n", - " dates = []\n", - " for date in glob.glob(r\"/raid/projects/akhot2/group-01-phys371-sp2023/data/\" + folder_name + \"/*\"):\n", - " dates.append(date)\n", - " for date in dates:\n", - " for image_file in glob.glob(date + \"/*\"):\n", - " print(image_file.split(\"/\")[-1])\n", - " f_name = image_file.split(\"/\")[-1]\n", - " #continue\n", - " if image_file.split(\".\")[-1].lower() == \"heic\":\n", - " heif_file = pillow_heif.read_heif(image_file)\n", - " img = Image.frombytes(\n", - " heif_file.mode,\n", - " heif_file.size,\n", - " heif_file.data,\n", - " \"raw\",\n", - " )\n", - " img.save(r\"/raid/projects/akhot2/group-01-phys371-sp2023/beetles/\"+f_name[:-4]+\".jpg\")\n", - " #print(\"HEIC FILE:\")\n", - " else:\n", - " img = Image.open(image_file)\n", - " img.save(r\"/raid/projects/akhot2/group-01-phys371-sp2023/beetles/\"+f_name)\n", - " #print(\"JPG FILE:\")\n", - " name = f_name.split(\"_\")[0]\n", - " if name[-1].isalpha():\n", - " name = name[0:-1]\n", - " day = f_name.split(\"_\")[1][0:2]\n", - " if day[1].isalpha():\n", - " day = \"0\" + day[0]\n", - " if \"august\" in f_name.lower():\n", - " date = \"2022-08-\" + day \n", - " else:\n", - " date = \"2022-07-\" + day\n", - " beetle_count = df_angled[(df_angled['2022 Data Collect. Date'] == date) & (df_angled['Sticky Trap Name'] == name)]['T-top side WCR']\n", - " row_number = beetle_count.index[0]\n", - " #total_beetles += int(beetle_count)\n", - " #images.append((img_tensor, int(beetle_count), row_number))\n", - " \n", - " \n", - " #plt.imshow(img)\n", - " #plt.show()\n", - " #print(img_tensor.shape)\n", - " \n", - " \n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "id": "eaa3da3e", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>Grand Acc #</th>\n", - " <th>Weekly Acc#</th>\n", - " <th>Sample collection period</th>\n", - " <th>Sticky trap pair (rep)</th>\n", - " <th>2022 Julian Date</th>\n", - " <th>Month</th>\n", - " <th>2022 Set up Date</th>\n", - " <th>2022 Data Collect. Date</th>\n", - " <th>Coll. intrvl (d)</th>\n", - " <th>Coll. hour</th>\n", - " <th>...</th>\n", - " <th>NCR/trap /day</th>\n", - " <th>WCR/trap /day</th>\n", - " <th>Total CRW /trap /day</th>\n", - " <th>NCR/trap top /day</th>\n", - " <th>WCR/trap top/day</th>\n", - " <th>Total CRW /trap top/day</th>\n", - " <th>Proportion NCR on top</th>\n", - " <th>Proportion WCR on top</th>\n", - " <th>Proportion All CRW on top</th>\n", - " <th>Notes</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " </tbody>\n", - "</table>\n", - "<p>0 rows × 43 columns</p>\n", - "</div>" - ], - "text/plain": [ - "Empty DataFrame\n", - "Columns: [Grand Acc #, Weekly Acc#, Sample collection period, Sticky trap pair (rep), 2022 Julian Date, Month, 2022 Set up Date, 2022 Data Collect. Date, Coll. intrvl (d), Coll. hour, Trap visitor, Drone pilot, On farm location, Site Abrv., trap angle, trap orient'n, Trap #, Sticky Trap Name, T-top side NCR, bottom side NCR, T-top side WCR, bottom side WCR, WCR mal, WCR fem, T-top side \"other\", Bottom side \"other\", T-top side total CRW, bottom side total CRW, Trap Total NCR, Trap Total WCR, Trap Total CRW, Proportion NCR in total CRW, Proportion WCR in total CRW, NCR/trap /day, WCR/trap /day, Total CRW /trap /day, NCR/trap top /day, WCR/trap top/day, Total CRW /trap top/day, Proportion NCR on top, Proportion WCR on top, Proportion All CRW on top, Notes]\n", - "Index: []\n", - "\n", - "[0 rows x 43 columns]" - ] - }, - "execution_count": 26, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df_angled[df_angled['2022 Data Collect. Date'] == \"2022-08-01\"]" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "id": "80679db4", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "41" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "total_beetles" - ] - }, - { - "cell_type": "code", - "execution_count": 44, - "id": "a397557a", - "metadata": {}, - "outputs": [], - "source": [ - "folder = '../data'\n", - "if not os.path.exists(folder):\n", - " os.mkdir(folder)\n", - "with open(folder+\"/training-data\"+\".pkl\", \"wb\") as f:\n", - " pickle.dump(images, f)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "997ccb7f", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.12" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/training/PreProcessor.ipynb b/training/PreProcessor.ipynb deleted file mode 100644 index bb4dbc980bbb0ed342fa7dc730c6915dfff3c2f9..0000000000000000000000000000000000000000 --- a/training/PreProcessor.ipynb +++ /dev/null @@ -1,677 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "ff555f6b", - "metadata": {}, - "outputs": [], - "source": [ - "import glob\n", - "from tqdm import tqdm\n", - "import pandas as pd \n", - "import torch\n", - "from PIL import Image\n", - "import torchvision.transforms as transforms\n", - "import matplotlib.pyplot as plt\n", - "import pillow_heif\n", - "import os\n", - "import pickle" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "fd6db132", - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/raid/projects/akhot2/conda/envs/akhot2/lib/python3.9/site-packages/openpyxl/worksheet/header_footer.py:48: UserWarning: Cannot parse header or footer so it will be ignored\n", - " warn(\"\"\"Cannot parse header or footer so it will be ignored\"\"\")\n" - ] - }, - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>Grand Acc #</th>\n", - " <th>Weekly Acc#</th>\n", - " <th>Sample collection period</th>\n", - " <th>Sticky trap pair (rep)</th>\n", - " <th>2022 Julian Date</th>\n", - " <th>Month</th>\n", - " <th>2022 Set up Date</th>\n", - " <th>2022 Data Collect. Date</th>\n", - " <th>Coll. intrvl (d)</th>\n", - " <th>Coll. hour</th>\n", - " <th>...</th>\n", - " <th>NCR/trap /day</th>\n", - " <th>WCR/trap /day</th>\n", - " <th>Total CRW /trap /day</th>\n", - " <th>NCR/trap top /day</th>\n", - " <th>WCR/trap top/day</th>\n", - " <th>Total CRW /trap top/day</th>\n", - " <th>Proportion NCR on top</th>\n", - " <th>Proportion WCR on top</th>\n", - " <th>Proportion All CRW on top</th>\n", - " <th>Notes</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>2</td>\n", - " <td>2</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>2022-07-08</td>\n", - " <td>2022-07-19</td>\n", - " <td>11.0</td>\n", - " <td>11.35</td>\n", - " <td>...</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>4</td>\n", - " <td>4</td>\n", - " <td>1</td>\n", - " <td>2</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>2022-07-08</td>\n", - " <td>2022-07-19</td>\n", - " <td>11.0</td>\n", - " <td>11.35</td>\n", - " <td>...</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>6</td>\n", - " <td>6</td>\n", - " <td>1</td>\n", - " <td>3</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>2022-07-08</td>\n", - " <td>2022-07-19</td>\n", - " <td>11.0</td>\n", - " <td>11.35</td>\n", - " <td>...</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>8</td>\n", - " <td>8</td>\n", - " <td>1</td>\n", - " <td>4</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>2022-07-08</td>\n", - " <td>2022-07-19</td>\n", - " <td>11.0</td>\n", - " <td>11.35</td>\n", - " <td>...</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>10</td>\n", - " <td>10</td>\n", - " <td>1</td>\n", - " <td>5</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>2022-07-08</td>\n", - " <td>2022-07-19</td>\n", - " <td>11.0</td>\n", - " <td>11.35</td>\n", - " <td>...</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " <td>NaN</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "<p>5 rows × 43 columns</p>\n", - "</div>" - ], - "text/plain": [ - " Grand Acc # Weekly Acc# Sample collection period Sticky trap pair (rep) \\\n", - "0 2 2 1 1 \n", - "1 4 4 1 2 \n", - "2 6 6 1 3 \n", - "3 8 8 1 4 \n", - "4 10 10 1 5 \n", - "\n", - " 2022 Julian Date Month 2022 Set up Date 2022 Data Collect. Date \\\n", - "0 NaN NaN 2022-07-08 2022-07-19 \n", - "1 NaN NaN 2022-07-08 2022-07-19 \n", - "2 NaN NaN 2022-07-08 2022-07-19 \n", - "3 NaN NaN 2022-07-08 2022-07-19 \n", - "4 NaN NaN 2022-07-08 2022-07-19 \n", - "\n", - " Coll. intrvl (d) Coll. hour ... NCR/trap /day WCR/trap /day \\\n", - "0 11.0 11.35 ... 0.0 0.0 \n", - "1 11.0 11.35 ... 0.0 0.0 \n", - "2 11.0 11.35 ... 0.0 0.0 \n", - "3 11.0 11.35 ... 0.0 0.0 \n", - "4 11.0 11.35 ... 0.0 0.0 \n", - "\n", - " Total CRW /trap /day NCR/trap top /day WCR/trap top/day \\\n", - "0 0.0 0.0 0.0 \n", - "1 0.0 0.0 0.0 \n", - "2 0.0 0.0 0.0 \n", - "3 0.0 0.0 0.0 \n", - "4 0.0 0.0 0.0 \n", - "\n", - " Total CRW /trap top/day Proportion NCR on top Proportion WCR on top \\\n", - "0 0.0 NaN NaN \n", - "1 0.0 NaN NaN \n", - "2 0.0 NaN NaN \n", - "3 0.0 NaN NaN \n", - "4 0.0 NaN NaN \n", - "\n", - " Proportion All CRW on top Notes \n", - "0 NaN NaN \n", - "1 NaN NaN \n", - "2 NaN NaN \n", - "3 NaN NaN \n", - "4 NaN NaN \n", - "\n", - "[5 rows x 43 columns]" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "labels_path = \"../data/trap_labels.xlsx\"\n", - "df = pd.read_excel(labels_path)\n", - "df.head()" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "7097a875", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Index(['Grand Acc #', 'Weekly Acc#', 'Sample collection period',\n", - " 'Sticky trap pair (rep)', '2022 Julian Date', 'Month',\n", - " '2022 Set up Date', '2022 Data Collect. Date', 'Coll. intrvl (d)',\n", - " 'Coll. hour', 'Trap visitor', 'Drone pilot', 'On farm location',\n", - " 'Site Abrv.', 'trap angle', 'trap orient'n', 'Trap #',\n", - " 'Sticky Trap Name', 'T-top side NCR', 'bottom side NCR',\n", - " 'T-top side WCR', 'bottom side WCR', 'WCR mal', 'WCR fem',\n", - " 'T-top side \"other\"', 'Bottom side \"other\"', 'T-top side total CRW',\n", - " 'bottom side total CRW', 'Trap Total NCR', 'Trap Total WCR',\n", - " 'Trap Total CRW', 'Proportion NCR in total CRW',\n", - " 'Proportion WCR in total CRW', 'NCR/trap /day', 'WCR/trap /day',\n", - " 'Total CRW /trap /day', 'NCR/trap top /day', 'WCR/trap top/day',\n", - " 'Total CRW /trap top/day', 'Proportion NCR on top',\n", - " 'Proportion WCR on top', 'Proportion All CRW on top', 'Notes'],\n", - " dtype='object')" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.columns" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "24d3874e", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>trap orient'n</th>\n", - " <th>2022 Data Collect. Date</th>\n", - " <th>Sticky Trap Name</th>\n", - " <th>T-top side WCR</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>Angled</td>\n", - " <td>2022-07-19</td>\n", - " <td>U2</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>Angled</td>\n", - " <td>2022-07-19</td>\n", - " <td>U4</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>Angled</td>\n", - " <td>2022-07-19</td>\n", - " <td>U6</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>Angled</td>\n", - " <td>2022-07-19</td>\n", - " <td>U8</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>Angled</td>\n", - " <td>2022-07-19</td>\n", - " <td>U10</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>...</th>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " </tr>\n", - " <tr>\n", - " <th>603</th>\n", - " <td>Angled</td>\n", - " <td>NaT</td>\n", - " <td>M24</td>\n", - " <td>nan</td>\n", - " </tr>\n", - " <tr>\n", - " <th>604</th>\n", - " <td>Angled</td>\n", - " <td>NaT</td>\n", - " <td>M26</td>\n", - " <td>nan</td>\n", - " </tr>\n", - " <tr>\n", - " <th>605</th>\n", - " <td>Angled</td>\n", - " <td>NaT</td>\n", - " <td>M28</td>\n", - " <td>nan</td>\n", - " </tr>\n", - " <tr>\n", - " <th>606</th>\n", - " <td>Angled</td>\n", - " <td>NaT</td>\n", - " <td>M30</td>\n", - " <td>nan</td>\n", - " </tr>\n", - " <tr>\n", - " <th>607</th>\n", - " <td>Angled</td>\n", - " <td>NaT</td>\n", - " <td>M32</td>\n", - " <td>nan</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "<p>320 rows × 4 columns</p>\n", - "</div>" - ], - "text/plain": [ - " trap orient'n 2022 Data Collect. Date Sticky Trap Name T-top side WCR\n", - "0 Angled 2022-07-19 U2 0\n", - "1 Angled 2022-07-19 U4 0\n", - "2 Angled 2022-07-19 U6 0\n", - "3 Angled 2022-07-19 U8 0\n", - "4 Angled 2022-07-19 U10 0\n", - ".. ... ... ... ...\n", - "603 Angled NaT M24 nan\n", - "604 Angled NaT M26 nan\n", - "605 Angled NaT M28 nan\n", - "606 Angled NaT M30 nan\n", - "607 Angled NaT M32 nan\n", - "\n", - "[320 rows x 4 columns]" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df_angled = df[df[\"trap orient'n\"] == \"Angled \"].astype(str)\n", - "df_angled[[\"trap orient'n\", \"2022 Data Collect. Date\", \"Sticky Trap Name\", \"T-top side WCR\"]]" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "b605c71f", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "B12_15August2022.jpg 421 2\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "B4_15August2022.jpg 417 2\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "B24_15August2022.jpg 427 2\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "B10_15August2022.jpg 420 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "B2_15August2022.jpg 416 2\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "B6_15August2022.jpg 418 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "B28_25August2022.jpg 525 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "B26_25August2022.jpg 524 3\n", - "Name: T-top side WCR, dtype: object\n", - "1\n", - "B24_25August2022.jpg 523 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "B2_25August2022.HEIC 512 1\n", - "Name: T-top side WCR, dtype: object\n", - "1\n", - "B18_25August2022.jpg 520 1\n", - "Name: T-top side WCR, dtype: object\n", - "6\n", - "B18c_25August2022.jpg 520 1\n", - "Name: T-top side WCR, dtype: object\n", - "6\n", - "B30_25August2022.jpg 526 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "B18b_25August2022.jpg 520 1\n", - "Name: T-top side WCR, dtype: object\n", - "6\n", - "B30b_25August2022.jpg 526 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "B2_3AUGUST2022.HEIC 256 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "B12_3AUGUST2022.HEIC 261 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "F2_3AUGUST2022.jpg 272 3\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "F28_3AUGUST2022.HEIC 285 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "F18_3AUGUST2022.HEIC 280 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "F10_3AUGUST2022.jpg 276 2\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "F16_3AUGUST2022.jpg 279 1\n", - "Name: T-top side WCR, dtype: object\n", - "1\n", - "F6_3AUGUST2022.jpg 274 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "F4_3AUGUST2022.jpg 273 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "F20_3AUGUST2022.HEIC 281 3\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "F32_3AUGUST2022.HEIC 287 1\n", - "Name: T-top side WCR, dtype: object\n", - "1\n", - "F14_3AUGUST2022.jpg 278 1\n", - "Name: T-top side WCR, dtype: object\n", - "1\n", - "F26_26JUL2022.HEIC 156 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n", - "F2_26JUL2022.jpg 144 1\n", - "Name: T-top side WCR, dtype: object\n", - "1\n", - "M10_19July2022.jpg 20 1\n", - "Name: T-top side WCR, dtype: object\n", - "0\n" - ] - } - ], - "source": [ - "## folders = [\"buchhloz\", \"faivre\", \"moore\", \"underwood\"]\n", - "\n", - "\n", - "images = []\n", - "total_beetles = 0\n", - "for folder_name in folders:\n", - " dates = []\n", - " for date in glob.glob(r\"/raid/projects/akhot2/group-01-phys371-sp2023/data/\" + folder_name + \"/*\"):\n", - " dates.append(date)\n", - " for date in dates:\n", - " for image_file in glob.glob(date + \"/*\"):\n", - " #print(image_file.split(\"/\")[-1])\n", - " f_name = image_file.split(\"/\")[-1]\n", - " #continue\n", - " if image_file.split(\".\")[-1].lower() == \"heic\":\n", - " heif_file = pillow_heif.read_heif(image_file)\n", - " img = Image.frombytes(\n", - " heif_file.mode,\n", - " heif_file.size,\n", - " heif_file.data,\n", - " \"raw\",\n", - " )\n", - " #print(r\"/raid/projects/akhot2/group-01-phys371-sp2023/beetles/\"+f_name[:-5]+\".jpg\")\n", - " #img.save(r\"/raid/projects/akhot2/group-01-phys371-sp2023/beetles/\"+f_name[:-5]+\".jpg\")\n", - " #print(\"HEIC FILE:\")\n", - " else:\n", - " img = Image.open(image_file)\n", - " #print(r\"/raid/projects/akhot2/group-01-phys371-sp2023/beetles/\"+f_name)\n", - " #img.save(r\"/raid/projects/akhot2/group-01-phys371-sp2023/beetles/\"+f_name)\n", - " #print(\"JPG FILE:\")\n", - " name = f_name.split(\"_\")[0]\n", - " if name[-1].isalpha():\n", - " name = name[0:-1]\n", - " day = f_name.split(\"_\")[1][0:2]\n", - " if day[1].isalpha():\n", - " day = \"0\" + day[0]\n", - " if \"august\" in f_name.lower():\n", - " date = \"2022-08-\" + day \n", - " else:\n", - " date = \"2022-07-\" + day\n", - " beetle_count = df_angled[(df_angled['2022 Data Collect. Date'] == date) & (df_angled['Sticky Trap Name'] == name)]['T-top side WCR']\n", - " row_number = beetle_count.index[0]\n", - " if (int(beetle_count) != 0):\n", - " print(f_name, beetle_count)\n", - " print(int(df_angled[(df_angled['2022 Data Collect. Date'] == date) & (df_angled['Sticky Trap Name'] == name)]['T-top side NCR']))\n", - " #total_beetles += int(beetle_count)\n", - " #images.append((img_tensor, int(beetle_count), row_number))\n", - " \n", - " \n", - " #plt.imshow(img)\n", - " #plt.show()\n", - " #print(img_tensor.shape)\n", - " \n", - " \n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "id": "80679db4", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "41" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "total_beetles" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "a397557a", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['/raid/projects/akhot2/group-01-phys371-sp2023/data/moore/M_7.19.22',\n", - " '/raid/projects/akhot2/group-01-phys371-sp2023/data/moore/M_8.4.22',\n", - " '/raid/projects/akhot2/group-01-phys371-sp2023/data/moore/M_8.17.22',\n", - " '/raid/projects/akhot2/group-01-phys371-sp2023/data/moore/M_7.27.22']" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dates" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "997ccb7f", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.12" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/training/dataloader.py b/training/dataloader.py deleted file mode 100644 index b12d444139013915e4b1dfd7233176ce133dc875..0000000000000000000000000000000000000000 --- a/training/dataloader.py +++ /dev/null @@ -1,103 +0,0 @@ -import os -import json -import torch -from torchvision.io import read_image -from torch.utils.data import Dataset -from torchvision.transforms import Compose -import torchvideo.transforms as tvt -from tqdm import tqdm -from torchvision.transforms import InterpolationMode -import pickle -import os - - -class ASLDataset(Dataset): - def __init__(self, file_path, size=256, transforms=None): - with open(file_path, "rb") as f: - data = pickle.load(f) - - - self.clips = [] - - self.labels = {} - total_classes = len(data) - current_class = 0 - - self.frames = frame - self.size = size - if transforms is None: - transforms = Compose([ - tvt.NormalizeVideo([0.485, 0.456, 0.406], [0.229, 0.224, 0.225], channel_dim=1), - tvt.ResizeVideo((size,size), interpolation=InterpolationMode.BICUBIC) - - ]) - - self.transforms = transforms - - for key in data: # for each word - one_hot_version = torch.nn.functional.one_hot(torch.tensor([current_class]), num_classes=total_classes) - - self.labels[key] = current_class # one_hot_version # make it the next one_hot - # word -> OHE - current_class += 1 - - for value in data[key]: - self.clips.append((key, value)) - - - def __len__(self): - return len(self.clips) - - def __getitem__(self, idx): - word, video_data = self.clips[idx] - # convert the word to a one hot encoding - label = self.labels[word] - - # convert the video data to be the same shape (and load the video) - frame_start, frame_end, video_url = video_data - # get the video path - video_path = "/raid/projects/weustis/data/asl/videos/"+ "_".join(video_url.split('/')[-2:]).split('.')[0] + "/" - # video_path = r"/raid/projects/weustis/data/asl/videos/ASL_2008_01_11_scene26-camera1/" - # load the video - path, dirs, files = next(os.walk(video_path)) - frame_count = len(files) - - # c, t, h, w - # specified frames and size beforehand - - # shorten/length the video - frame_end = int(frame_end) - frame_start = int(frame_start) - t = frame_end - frame_start #time of video - - - if (t < self.frames): #if shorter - offset = torch.randint(t-self.frames, 0, (1,)) + 1 - - if (t > self.frames): - offset = torch.randint(t-self.frames, (1,)) - else: - offset = 0 - frames = ["%06d" % (x,)+".jpg" for x in range(frame_start+offset, frame_start+offset+self.frames)] - r = torch.empty(self.frames, 3, 480, 640) - for idx, p_end in enumerate(frames): - img_data = read_image(video_path + p_end) - r[idx, :, :, :] = img_data - # resize video - r = r.permute([1,0,2,3]).unsqueeze(0) - r = next(self.transforms(r)) - - return r, label - -if __name__ == "__main__": - - mydataset = ASLDataset("/raid/projects/weustis/data/asl/dataset.json") - - from torch.utils.data import DataLoader - - dataloader = DataLoader(mydataset, batch_size=8, shuffle=True, num_workers=40, pin_memory=True, prefetch_factor=1, persistent_workers=True) - - for x,y in tqdm(dataloader): - pass - - # python dataloader.py \ No newline at end of file diff --git a/training/preprocess.py b/training/preprocess.py deleted file mode 100644 index 3bcb59843994110fd680d73a76c24f4b81a75cde..0000000000000000000000000000000000000000 --- a/training/preprocess.py +++ /dev/null @@ -1,75 +0,0 @@ -import glob -from tqdm import tqdm -import pandas as pd -import torch -from PIL import Image -import torchvision.transforms as transforms -import matplotlib.pyplot as plt -import pillow_heif -import os -import pickle - -labels_path = "../data/trap_labels.xlsx" -df = pd.read_excel(labels_path) - -df_angled = df[df["trap orient'n"] == "Angled "].astype(str) - -folders = ["buchhloz", "faivre", "moore", "underwood"] - -transform = transforms.Compose([ - transforms.PILToTensor() -]) - -print("Loading images...") - -images = [] -total_beetles = 0 -for folder_name in folders: - dates = [] - for date in glob.glob(r"/raid/projects/akhot2/group-01-phys371-sp2023/data/" + folder_name + "/*"): - dates.append(date) - for date in dates: - for image_file in glob.glob(date + "/*"): - #print(image_file.split("/")[-1]) - f_name = image_file.split("/")[-1] - #continue - if image_file.split(".")[-1].lower() == "heic": - heif_file = pillow_heif.read_heif(image_file) - img = Image.frombytes( - heif_file.mode, - heif_file.size, - heif_file.data, - "raw", - ) - #print("HEIC FILE:") - else: - img = Image.open(image_file) - #print("JPG FILE:") - img_tensor = transform(img) - name = f_name.split("_")[0] - if name[-1].isalpha(): - name = name[0:-1] - day = f_name.split("_")[1][0:2] - if day[1].isalpha(): - day = "0" + day[0] - if "august" in f_name.lower(): - date = "2022-08-" + day - else: - date = "2022-07-" + day - beetle_count = df_angled[(df_angled['2022 Data Collect. Date'] == date) & (df_angled['Sticky Trap Name'] == name)]['T-top side WCR'] - row_number = beetle_count.index[0] - #total_beetles += int(beetle_count) - images.append((img_tensor, int(beetle_count), row_number)) - #plt.imshow(img) - #plt.show() - #print(img_tensor.shape) - -print("Loading images complete!") - -folder = '../data' -print("Uploading data to " + folder +"/training-data"+".pkl") -if not os.path.exists(folder): - os.mkdir(folder) -with open(folder+"/training-data"+".pkl", "wb") as f: - pickle.dump(images, f) - \ No newline at end of file diff --git a/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best-fp16.tflite b/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best-fp16.tflite deleted file mode 100644 index 9bb9801ebdaa6c286115347477c7f89c5e1c2cd9..0000000000000000000000000000000000000000 Binary files a/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best-fp16.tflite and /dev/null differ diff --git a/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best_saved_model/saved_model.pb b/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best_saved_model/saved_model.pb deleted file mode 100644 index 7596672b4772b30be6bb0e004ff0fad61ddc29f4..0000000000000000000000000000000000000000 Binary files a/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best_saved_model/saved_model.pb and /dev/null differ diff --git a/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best_saved_model/variables/variables.data-00000-of-00001 b/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best_saved_model/variables/variables.data-00000-of-00001 deleted file mode 100644 index 27a449672b10917813a3e70414ca7e7542f83da6..0000000000000000000000000000000000000000 Binary files a/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best_saved_model/variables/variables.data-00000-of-00001 and /dev/null differ diff --git a/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best_saved_model/variables/variables.index b/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best_saved_model/variables/variables.index deleted file mode 100644 index b10c8f79d1a39bc2938e0403b6c1e86dda405980..0000000000000000000000000000000000000000 Binary files a/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best_saved_model/variables/variables.index and /dev/null differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/F1_curve.png b/yolov5_model/runs/train/many_small_bugs_final/F1_curve.png new file mode 100644 index 0000000000000000000000000000000000000000..4b018bf4cea994f23a5f2dcdbb068a25851f6370 Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/F1_curve.png differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/PR_curve.png b/yolov5_model/runs/train/many_small_bugs_final/PR_curve.png new file mode 100644 index 0000000000000000000000000000000000000000..09742e0d8a2860f2fbe2b23fc6d9ade9f762b5bf Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/PR_curve.png differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/P_curve.png b/yolov5_model/runs/train/many_small_bugs_final/P_curve.png new file mode 100644 index 0000000000000000000000000000000000000000..99df6a670a8a449b90238d76918b954c980c4ad9 Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/P_curve.png differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/R_curve.png b/yolov5_model/runs/train/many_small_bugs_final/R_curve.png new file mode 100644 index 0000000000000000000000000000000000000000..6d4f7b3bc7902c6c1ec8dde99b90448cbff34f3f Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/R_curve.png differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/confusion_matrix.png b/yolov5_model/runs/train/many_small_bugs_final/confusion_matrix.png new file mode 100644 index 0000000000000000000000000000000000000000..a1d7cf298949c2daf6db77f7d06866d63789c0da Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/confusion_matrix.png differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/events.out.tfevents.1681314803.hal-dgx.163563.0 b/yolov5_model/runs/train/many_small_bugs_final/events.out.tfevents.1681314803.hal-dgx.163563.0 new file mode 100644 index 0000000000000000000000000000000000000000..8c7636924034dd7db1775f9f7e52d887a26aae1d Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/events.out.tfevents.1681314803.hal-dgx.163563.0 differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/hyp.yaml b/yolov5_model/runs/train/many_small_bugs_final/hyp.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fa80eb95531dba10a6c94a7651f781f8c99566be --- /dev/null +++ b/yolov5_model/runs/train/many_small_bugs_final/hyp.yaml @@ -0,0 +1,28 @@ +lr0: 0.01 +lrf: 0.01 +momentum: 0.937 +weight_decay: 0.0005 +warmup_epochs: 3.0 +warmup_momentum: 0.8 +warmup_bias_lr: 0.1 +box: 0.05 +cls: 0.5 +cls_pw: 1.0 +obj: 1.0 +obj_pw: 1.0 +iou_t: 0.2 +anchor_t: 4.0 +fl_gamma: 0.0 +hsv_h: 0.015 +hsv_s: 0.7 +hsv_v: 0.4 +degrees: 0.0 +translate: 0.1 +scale: 0.5 +shear: 0.0 +perspective: 0.0 +flipud: 0.0 +fliplr: 0.5 +mosaic: 1.0 +mixup: 0.0 +copy_paste: 0.0 diff --git a/yolov5_model/runs/train/many_small_bugs_final/labels.jpg b/yolov5_model/runs/train/many_small_bugs_final/labels.jpg new file mode 100644 index 0000000000000000000000000000000000000000..391e0d9ccd2438d11914767ac08b9377f1ab7734 Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/labels.jpg differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/labels_correlogram.jpg b/yolov5_model/runs/train/many_small_bugs_final/labels_correlogram.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4c51757a0a34b9b99b14d91a04a5ea7a1fead7b4 Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/labels_correlogram.jpg differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/opt.yaml b/yolov5_model/runs/train/many_small_bugs_final/opt.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d1e66fb1063ec5855366173760860a7c4ea2120d --- /dev/null +++ b/yolov5_model/runs/train/many_small_bugs_final/opt.yaml @@ -0,0 +1,68 @@ +weights: yolov5m.pt +cfg: '' +data: /projects/akhot2/group-01-phys371-sp2023/yolov5_model/data/beetles.yaml +hyp: + lr0: 0.01 + lrf: 0.01 + momentum: 0.937 + weight_decay: 0.0005 + warmup_epochs: 3.0 + warmup_momentum: 0.8 + warmup_bias_lr: 0.1 + box: 0.05 + cls: 0.5 + cls_pw: 1.0 + obj: 1.0 + obj_pw: 1.0 + iou_t: 0.2 + anchor_t: 4.0 + fl_gamma: 0.0 + hsv_h: 0.015 + hsv_s: 0.7 + hsv_v: 0.4 + degrees: 0.0 + translate: 0.1 + scale: 0.5 + shear: 0.0 + perspective: 0.0 + flipud: 0.0 + fliplr: 0.5 + mosaic: 1.0 + mixup: 0.0 + copy_paste: 0.0 +epochs: 100 +batch_size: 16 +imgsz: 1280 +rect: false +resume: false +nosave: false +noval: false +noautoanchor: false +noplots: false +evolve: null +bucket: '' +cache: null +image_weights: false +device: '' +multi_scale: false +single_cls: false +optimizer: SGD +sync_bn: false +workers: 30 +project: runs/train +name: many_small_bugs_final +exist_ok: false +quad: false +cos_lr: false +label_smoothing: 0.0 +patience: 100 +freeze: +- 0 +save_period: -1 +seed: 0 +local_rank: -1 +entity: null +upload_dataset: false +bbox_interval: -1 +artifact_alias: latest +save_dir: runs/train/many_small_bugs_final2 diff --git a/yolov5_model/runs/train/many_small_bugs_final/results.csv b/yolov5_model/runs/train/many_small_bugs_final/results.csv new file mode 100644 index 0000000000000000000000000000000000000000..16ec7bcc6c68d37df20dfa9f80f0d67f3606f218 --- /dev/null +++ b/yolov5_model/runs/train/many_small_bugs_final/results.csv @@ -0,0 +1,101 @@ + epoch, train/box_loss, train/obj_loss, train/cls_loss, metrics/precision, metrics/recall, metrics/mAP_0.5,metrics/mAP_0.5:0.95, val/box_loss, val/obj_loss, val/cls_loss, x/lr0, x/lr1, x/lr2 + 0, 0.097243, 0.06281, 0, 0.17347, 0.27562, 0.1363, 0.040525, 0.071902, 0.06122, 0, 0.070476, 0.0032804, 0.0032804 + 1, 0.070225, 0.044764, 0, 0.2465, 0.45936, 0.25584, 0.067728, 0.077623, 0.030969, 0, 0.040411, 0.0065483, 0.0065483 + 2, 0.065579, 0.035301, 0, 0.39675, 0.47177, 0.44328, 0.21937, 0.069474, 0.027863, 0, 0.010279, 0.0097501, 0.0097501 + 3, 0.058981, 0.032821, 0, 0.3653, 0.69376, 0.41495, 0.19233, 0.05077, 0.02667, 0, 0.009703, 0.009703, 0.009703 + 4, 0.052421, 0.028862, 0, 0.88261, 0.86219, 0.90765, 0.38392, 0.043266, 0.026048, 0, 0.009703, 0.009703, 0.009703 + 5, 0.047319, 0.027349, 0, 0.71385, 0.83274, 0.78506, 0.36881, 0.042299, 0.024506, 0, 0.009604, 0.009604, 0.009604 + 6, 0.044794, 0.023887, 0, 0.88028, 0.84875, 0.91111, 0.38426, 0.046013, 0.022887, 0, 0.009505, 0.009505, 0.009505 + 7, 0.043812, 0.023888, 0, 0.97928, 0.96231, 0.97947, 0.52815, 0.037914, 0.021424, 0, 0.009406, 0.009406, 0.009406 + 8, 0.040993, 0.023779, 0, 0.84504, 0.8033, 0.85004, 0.37631, 0.039348, 0.032721, 0, 0.009307, 0.009307, 0.009307 + 9, 0.039937, 0.022211, 0, 0.94882, 0.9576, 0.97004, 0.52214, 0.038863, 0.020727, 0, 0.009208, 0.009208, 0.009208 + 10, 0.038218, 0.022502, 0, 0.9617, 0.94642, 0.97072, 0.46507, 0.034115, 0.020018, 0, 0.009109, 0.009109, 0.009109 + 11, 0.037523, 0.019791, 0, 0.97851, 0.9656, 0.98951, 0.5587, 0.032443, 0.020152, 0, 0.00901, 0.00901, 0.00901 + 12, 0.037467, 0.020859, 0, 0.978, 0.97998, 0.99295, 0.6221, 0.028839, 0.018386, 0, 0.008911, 0.008911, 0.008911 + 13, 0.035102, 0.019882, 0, 0.97175, 0.97248, 0.98926, 0.58842, 0.030197, 0.0201, 0, 0.008812, 0.008812, 0.008812 + 14, 0.034571, 0.019543, 0, 0.97455, 0.97998, 0.99187, 0.61194, 0.027963, 0.019409, 0, 0.008713, 0.008713, 0.008713 + 15, 0.035235, 0.01989, 0, 0.9255, 0.91284, 0.96718, 0.53774, 0.033411, 0.024132, 0, 0.008614, 0.008614, 0.008614 + 16, 0.033208, 0.019656, 0, 0.92944, 0.91537, 0.95249, 0.47981, 0.037749, 0.023129, 0, 0.008515, 0.008515, 0.008515 + 17, 0.03407, 0.019406, 0, 0.98561, 0.96838, 0.9927, 0.58853, 0.027547, 0.018005, 0, 0.008416, 0.008416, 0.008416 + 18, 0.032947, 0.018555, 0, 0.99193, 0.97173, 0.99315, 0.63542, 0.02781, 0.01919, 0, 0.008317, 0.008317, 0.008317 + 19, 0.032025, 0.018749, 0, 0.92739, 0.96274, 0.98179, 0.63313, 0.025915, 0.022055, 0, 0.008218, 0.008218, 0.008218 + 20, 0.030589, 0.01807, 0, 0.98238, 0.98516, 0.99054, 0.61339, 0.026677, 0.017889, 0, 0.008119, 0.008119, 0.008119 + 21, 0.030634, 0.017255, 0, 0.99392, 0.98704, 0.99446, 0.62184, 0.029601, 0.017627, 0, 0.00802, 0.00802, 0.00802 + 22, 0.029916, 0.01747, 0, 0.99615, 0.98469, 0.99463, 0.68228, 0.024839, 0.016924, 0, 0.007921, 0.007921, 0.007921 + 23, 0.030228, 0.017375, 0, 0.98141, 0.99513, 0.99461, 0.66011, 0.025175, 0.016227, 0, 0.007822, 0.007822, 0.007822 + 24, 0.029303, 0.017656, 0, 0.97328, 0.97527, 0.99072, 0.65001, 0.025586, 0.018267, 0, 0.007723, 0.007723, 0.007723 + 25, 0.02934, 0.017284, 0, 0.99406, 0.98519, 0.99477, 0.67472, 0.024848, 0.016064, 0, 0.007624, 0.007624, 0.007624 + 26, 0.028122, 0.017042, 0, 0.97593, 0.95532, 0.9879, 0.58973, 0.029238, 0.018598, 0, 0.007525, 0.007525, 0.007525 + 27, 0.02804, 0.017262, 0, 0.98585, 0.98451, 0.99454, 0.70645, 0.022739, 0.016057, 0, 0.007426, 0.007426, 0.007426 + 28, 0.027497, 0.017088, 0, 0.98007, 0.9894, 0.99401, 0.69219, 0.02366, 0.016421, 0, 0.007327, 0.007327, 0.007327 + 29, 0.027131, 0.016037, 0, 0.9976, 0.97833, 0.99466, 0.71791, 0.021688, 0.015894, 0, 0.007228, 0.007228, 0.007228 + 30, 0.027151, 0.015747, 0, 0.98698, 0.97527, 0.9942, 0.70909, 0.021914, 0.015985, 0, 0.007129, 0.007129, 0.007129 + 31, 0.026047, 0.015519, 0, 0.98589, 0.98791, 0.99385, 0.70078, 0.022224, 0.015663, 0, 0.00703, 0.00703, 0.00703 + 32, 0.025975, 0.015528, 0, 0.99245, 0.98469, 0.99474, 0.70781, 0.023604, 0.016006, 0, 0.006931, 0.006931, 0.006931 + 33, 0.025168, 0.015869, 0, 0.99061, 0.99529, 0.99491, 0.71747, 0.022568, 0.015658, 0, 0.006832, 0.006832, 0.006832 + 34, 0.025439, 0.015402, 0, 0.99641, 0.9894, 0.99487, 0.74356, 0.021262, 0.014931, 0, 0.006733, 0.006733, 0.006733 + 35, 0.024626, 0.01503, 0, 0.99882, 0.99361, 0.995, 0.73345, 0.021466, 0.014718, 0, 0.006634, 0.006634, 0.006634 + 36, 0.02456, 0.015237, 0, 0.99646, 0.99379, 0.99498, 0.73196, 0.020825, 0.014325, 0, 0.006535, 0.006535, 0.006535 + 37, 0.024127, 0.01501, 0, 0.99881, 0.99001, 0.99499, 0.73638, 0.019606, 0.014337, 0, 0.006436, 0.006436, 0.006436 + 38, 0.023861, 0.015081, 0, 0.99533, 0.98822, 0.99492, 0.74662, 0.020558, 0.014443, 0, 0.006337, 0.006337, 0.006337 + 39, 0.023294, 0.014307, 0, 0.99663, 0.99058, 0.99499, 0.76002, 0.019574, 0.013888, 0, 0.006238, 0.006238, 0.006238 + 40, 0.023427, 0.014474, 0, 0.99646, 0.99371, 0.99498, 0.76305, 0.018968, 0.013509, 0, 0.006139, 0.006139, 0.006139 + 41, 0.022525, 0.014231, 0, 0.99526, 0.98877, 0.99494, 0.76067, 0.019527, 0.014142, 0, 0.00604, 0.00604, 0.00604 + 42, 0.022108, 0.014528, 0, 0.99763, 0.99225, 0.99499, 0.77104, 0.018117, 0.01344, 0, 0.005941, 0.005941, 0.005941 + 43, 0.022152, 0.013893, 0, 0.99987, 0.98822, 0.99491, 0.76788, 0.01854, 0.013764, 0, 0.005842, 0.005842, 0.005842 + 44, 0.021764, 0.013708, 0, 1, 0.99347, 0.995, 0.76727, 0.018344, 0.013509, 0, 0.005743, 0.005743, 0.005743 + 45, 0.02123, 0.013782, 0, 0.9777, 0.98124, 0.99419, 0.74459, 0.019194, 0.015816, 0, 0.005644, 0.005644, 0.005644 + 46, 0.021438, 0.013921, 0, 1, 0.99247, 0.995, 0.77478, 0.018396, 0.013344, 0, 0.005545, 0.005545, 0.005545 + 47, 0.020683, 0.013575, 0, 0.99528, 0.99396, 0.99493, 0.78137, 0.017761, 0.013296, 0, 0.005446, 0.005446, 0.005446 + 48, 0.021378, 0.013379, 0, 0.99715, 0.99176, 0.99493, 0.76036, 0.019632, 0.014154, 0, 0.005347, 0.005347, 0.005347 + 49, 0.020632, 0.013024, 0, 0.99836, 0.99411, 0.995, 0.76713, 0.017843, 0.013545, 0, 0.005248, 0.005248, 0.005248 + 50, 0.020202, 0.013424, 0, 0.99277, 0.99411, 0.99494, 0.77523, 0.017839, 0.013704, 0, 0.005149, 0.005149, 0.005149 + 51, 0.019988, 0.012926, 0, 0.99764, 0.99377, 0.995, 0.78726, 0.017005, 0.012772, 0, 0.00505, 0.00505, 0.00505 + 52, 0.020192, 0.013268, 0, 0.99739, 0.99293, 0.99499, 0.77619, 0.019465, 0.013351, 0, 0.004951, 0.004951, 0.004951 + 53, 0.019478, 0.012897, 0, 0.9941, 0.99295, 0.99454, 0.78095, 0.01758, 0.013491, 0, 0.004852, 0.004852, 0.004852 + 54, 0.019491, 0.013534, 0, 1, 0.99391, 0.995, 0.80012, 0.015658, 0.012206, 0, 0.004753, 0.004753, 0.004753 + 55, 0.018868, 0.012575, 0, 0.99763, 0.99261, 0.995, 0.8051, 0.015482, 0.012202, 0, 0.004654, 0.004654, 0.004654 + 56, 0.018368, 0.012343, 0, 0.99882, 0.99372, 0.99499, 0.79554, 0.015885, 0.012517, 0, 0.004555, 0.004555, 0.004555 + 57, 0.018358, 0.012573, 0, 0.99962, 0.99176, 0.995, 0.79747, 0.017501, 0.012602, 0, 0.004456, 0.004456, 0.004456 + 58, 0.018495, 0.012696, 0, 0.99644, 0.98936, 0.99493, 0.7947, 0.016634, 0.013011, 0, 0.004357, 0.004357, 0.004357 + 59, 0.017957, 0.012255, 0, 0.99785, 0.9894, 0.99498, 0.79807, 0.016098, 0.012777, 0, 0.004258, 0.004258, 0.004258 + 60, 0.017677, 0.01244, 0, 0.99973, 0.99176, 0.995, 0.81346, 0.015261, 0.011922, 0, 0.004159, 0.004159, 0.004159 + 61, 0.017547, 0.011601, 0, 0.99721, 0.99764, 0.995, 0.80681, 0.015691, 0.012161, 0, 0.00406, 0.00406, 0.00406 + 62, 0.017373, 0.01255, 0, 0.99882, 0.99405, 0.995, 0.81523, 0.015155, 0.011916, 0, 0.003961, 0.003961, 0.003961 + 63, 0.017527, 0.011878, 0, 0.99732, 0.99529, 0.995, 0.81616, 0.015003, 0.011815, 0, 0.003862, 0.003862, 0.003862 + 64, 0.016569, 0.011364, 0, 0.99961, 0.99529, 0.995, 0.81802, 0.015239, 0.011704, 0, 0.003763, 0.003763, 0.003763 + 65, 0.016969, 0.012046, 0, 0.99988, 0.99529, 0.995, 0.81257, 0.01532, 0.011801, 0, 0.003664, 0.003664, 0.003664 + 66, 0.01668, 0.011756, 0, 0.99864, 0.99647, 0.995, 0.81662, 0.014721, 0.011514, 0, 0.003565, 0.003565, 0.003565 + 67, 0.016564, 0.011592, 0, 0.99643, 0.98692, 0.99492, 0.79157, 0.017407, 0.014044, 0, 0.003466, 0.003466, 0.003466 + 68, 0.016348, 0.01174, 0, 0.99846, 0.99411, 0.99414, 0.81303, 0.01571, 0.012085, 0, 0.003367, 0.003367, 0.003367 + 69, 0.015819, 0.01167, 0, 0.99997, 0.99293, 0.995, 0.82591, 0.014576, 0.011645, 0, 0.003268, 0.003268, 0.003268 + 70, 0.015782, 0.011217, 0, 0.99763, 0.99174, 0.99498, 0.82511, 0.014339, 0.011737, 0, 0.003169, 0.003169, 0.003169 + 71, 0.015883, 0.011354, 0, 0.99764, 0.9962, 0.995, 0.81732, 0.014572, 0.011498, 0, 0.00307, 0.00307, 0.00307 + 72, 0.015558, 0.010974, 0, 0.99737, 0.99764, 0.995, 0.82201, 0.014928, 0.01141, 0, 0.002971, 0.002971, 0.002971 + 73, 0.015005, 0.010958, 0, 0.99754, 0.99293, 0.995, 0.82048, 0.014642, 0.011627, 0, 0.002872, 0.002872, 0.002872 + 74, 0.014866, 0.010806, 0, 0.99764, 0.9963, 0.995, 0.8297, 0.014013, 0.011313, 0, 0.002773, 0.002773, 0.002773 + 75, 0.014422, 0.010927, 0, 0.99882, 0.99646, 0.995, 0.8302, 0.013903, 0.011206, 0, 0.002674, 0.002674, 0.002674 + 76, 0.014869, 0.011228, 0, 0.99851, 0.99529, 0.995, 0.83291, 0.01395, 0.011322, 0, 0.002575, 0.002575, 0.002575 + 77, 0.014233, 0.010874, 0, 0.99882, 0.99644, 0.995, 0.83062, 0.013872, 0.011094, 0, 0.002476, 0.002476, 0.002476 + 78, 0.014089, 0.010684, 0, 1, 0.99155, 0.995, 0.81989, 0.014532, 0.011738, 0, 0.002377, 0.002377, 0.002377 + 79, 0.014098, 0.010592, 0, 0.99731, 0.99647, 0.99499, 0.83346, 0.013849, 0.011476, 0, 0.002278, 0.002278, 0.002278 + 80, 0.014051, 0.010466, 0, 0.99868, 0.99411, 0.995, 0.83845, 0.013556, 0.011179, 0, 0.002179, 0.002179, 0.002179 + 81, 0.01361, 0.010217, 0, 0.99764, 0.99528, 0.995, 0.83721, 0.013542, 0.011015, 0, 0.00208, 0.00208, 0.00208 + 82, 0.013764, 0.010907, 0, 0.99844, 0.99647, 0.995, 0.83749, 0.01333, 0.011074, 0, 0.001981, 0.001981, 0.001981 + 83, 0.013152, 0.010106, 0, 0.99759, 0.99647, 0.995, 0.84295, 0.013205, 0.010723, 0, 0.001882, 0.001882, 0.001882 + 84, 0.013306, 0.010664, 0, 0.99848, 0.99529, 0.995, 0.8413, 0.013426, 0.01103, 0, 0.001783, 0.001783, 0.001783 + 85, 0.013221, 0.010594, 0, 0.99883, 0.99411, 0.995, 0.83901, 0.013572, 0.011198, 0, 0.001684, 0.001684, 0.001684 + 86, 0.01247, 0.0098534, 0, 0.99858, 0.99647, 0.995, 0.8484, 0.01296, 0.01067, 0, 0.001585, 0.001585, 0.001585 + 87, 0.012571, 0.0096862, 0, 0.99882, 0.99638, 0.995, 0.8441, 0.013161, 0.010701, 0, 0.001486, 0.001486, 0.001486 + 88, 0.012811, 0.010063, 0, 0.99647, 0.9961, 0.995, 0.84923, 0.012812, 0.010683, 0, 0.001387, 0.001387, 0.001387 + 89, 0.012625, 0.0099061, 0, 0.9988, 0.99647, 0.995, 0.85223, 0.012846, 0.010794, 0, 0.001288, 0.001288, 0.001288 + 90, 0.012561, 0.0099529, 0, 0.99813, 0.99176, 0.99499, 0.83975, 0.013285, 0.011014, 0, 0.001189, 0.001189, 0.001189 + 91, 0.012208, 0.0097584, 0, 0.99867, 0.99647, 0.995, 0.84677, 0.012738, 0.010521, 0, 0.00109, 0.00109, 0.00109 + 92, 0.012362, 0.0096287, 0, 0.99882, 0.99519, 0.995, 0.8504, 0.012696, 0.010389, 0, 0.000991, 0.000991, 0.000991 + 93, 0.012266, 0.0096319, 0, 0.99882, 0.99353, 0.995, 0.85183, 0.012567, 0.010277, 0, 0.000892, 0.000892, 0.000892 + 94, 0.012121, 0.0097769, 0, 1, 0.99482, 0.995, 0.8512, 0.012466, 0.010445, 0, 0.000793, 0.000793, 0.000793 + 95, 0.012114, 0.0092166, 0, 0.99865, 0.99411, 0.995, 0.85111, 0.012586, 0.010496, 0, 0.000694, 0.000694, 0.000694 + 96, 0.012028, 0.0097642, 0, 0.99977, 0.99411, 0.995, 0.8515, 0.012473, 0.010377, 0, 0.000595, 0.000595, 0.000595 + 97, 0.011675, 0.0092664, 0, 0.99882, 0.99501, 0.995, 0.85507, 0.012391, 0.010194, 0, 0.000496, 0.000496, 0.000496 + 98, 0.01188, 0.0096992, 0, 0.99995, 0.99411, 0.995, 0.85209, 0.012596, 0.010508, 0, 0.000397, 0.000397, 0.000397 + 99, 0.011424, 0.0090843, 0, 0.99976, 0.99411, 0.995, 0.85547, 0.01254, 0.010389, 0, 0.000298, 0.000298, 0.000298 diff --git a/yolov5_model/runs/train/many_small_bugs_final/results.png b/yolov5_model/runs/train/many_small_bugs_final/results.png new file mode 100644 index 0000000000000000000000000000000000000000..c08f18a39cf76e45f3c346832e2e6ff2234e0bbf Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/results.png differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/train_batch0.jpg b/yolov5_model/runs/train/many_small_bugs_final/train_batch0.jpg new file mode 100644 index 0000000000000000000000000000000000000000..02673ae26afb0dedbead81e9eb97c1bef63e2b6d Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/train_batch0.jpg differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/train_batch1.jpg b/yolov5_model/runs/train/many_small_bugs_final/train_batch1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..df23fc11b3fe17d7e2be915c1eb970ad3aea4caf Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/train_batch1.jpg differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/train_batch2.jpg b/yolov5_model/runs/train/many_small_bugs_final/train_batch2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b6aa655f15766c7a733192e44fcbed2115fd7397 Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/train_batch2.jpg differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/val_batch0_labels.jpg b/yolov5_model/runs/train/many_small_bugs_final/val_batch0_labels.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6eedaf2681445d419ab6a913f73e8e29efbb7757 Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/val_batch0_labels.jpg differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/val_batch0_pred.jpg b/yolov5_model/runs/train/many_small_bugs_final/val_batch0_pred.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b7e290d79db0756ae13a1f5034b878c3e1be95f9 Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/val_batch0_pred.jpg differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/val_batch1_labels.jpg b/yolov5_model/runs/train/many_small_bugs_final/val_batch1_labels.jpg new file mode 100644 index 0000000000000000000000000000000000000000..67677f42a67bb2dc350749d78382f7166abde4e1 Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/val_batch1_labels.jpg differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/val_batch1_pred.jpg b/yolov5_model/runs/train/many_small_bugs_final/val_batch1_pred.jpg new file mode 100644 index 0000000000000000000000000000000000000000..08dfc7e55522f90c8689ee5328cd6681d1ca3dad Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/val_batch1_pred.jpg differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/val_batch2_labels.jpg b/yolov5_model/runs/train/many_small_bugs_final/val_batch2_labels.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c89cbb9574a93c2a91bff4aa869347a72795a1d0 Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/val_batch2_labels.jpg differ diff --git a/yolov5_model/runs/train/many_small_bugs_final/val_batch2_pred.jpg b/yolov5_model/runs/train/many_small_bugs_final/val_batch2_pred.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0ffa36f3ac5091da8693865ed4ddc0a6b2027a9d Binary files /dev/null and b/yolov5_model/runs/train/many_small_bugs_final/val_batch2_pred.jpg differ diff --git a/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best.pt b/yolov5_model/runs/train/many_small_bugs_final/weights/best.pt similarity index 77% rename from yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best.pt rename to yolov5_model/runs/train/many_small_bugs_final/weights/best.pt index 3272769ed7aa27b97cbe96d37fd853d6374e418e..3cfbf39a9fedc72dcc7d3f0309a6303d47c70d03 100644 Binary files a/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/best.pt and b/yolov5_model/runs/train/many_small_bugs_final/weights/best.pt differ diff --git a/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/last.pt b/yolov5_model/runs/train/many_small_bugs_final/weights/last.pt similarity index 77% rename from yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/last.pt rename to yolov5_model/runs/train/many_small_bugs_final/weights/last.pt index 3272769ed7aa27b97cbe96d37fd853d6374e418e..3cfbf39a9fedc72dcc7d3f0309a6303d47c70d03 100644 Binary files a/yolov5_model/runs/train/6beetle_7-non_3dirt_bkg_over/weights/last.pt and b/yolov5_model/runs/train/many_small_bugs_final/weights/last.pt differ diff --git a/yolov5_model/runs/val/many_small_bugs_final/F1_curve.png b/yolov5_model/runs/val/many_small_bugs_final/F1_curve.png new file mode 100644 index 0000000000000000000000000000000000000000..83590f2e7a00c3451e9f1ff4761a7972859839f4 Binary files /dev/null and b/yolov5_model/runs/val/many_small_bugs_final/F1_curve.png differ diff --git a/yolov5_model/runs/val/many_small_bugs_final/PR_curve.png b/yolov5_model/runs/val/many_small_bugs_final/PR_curve.png new file mode 100644 index 0000000000000000000000000000000000000000..d3bb395f8c7e9db4c8d940567b86c1b54a6c98e5 Binary files /dev/null and b/yolov5_model/runs/val/many_small_bugs_final/PR_curve.png differ diff --git a/yolov5_model/runs/val/many_small_bugs_final/P_curve.png b/yolov5_model/runs/val/many_small_bugs_final/P_curve.png new file mode 100644 index 0000000000000000000000000000000000000000..2ab7501c2a19745857dca1853ea81b492c270965 Binary files /dev/null and b/yolov5_model/runs/val/many_small_bugs_final/P_curve.png differ diff --git a/yolov5_model/runs/val/many_small_bugs_final/R_curve.png b/yolov5_model/runs/val/many_small_bugs_final/R_curve.png new file mode 100644 index 0000000000000000000000000000000000000000..20edb490516cf6b1bb98b13644a9eea72c50bb14 Binary files /dev/null and b/yolov5_model/runs/val/many_small_bugs_final/R_curve.png differ diff --git a/yolov5_model/runs/val/many_small_bugs_final/confusion_matrix.png b/yolov5_model/runs/val/many_small_bugs_final/confusion_matrix.png new file mode 100644 index 0000000000000000000000000000000000000000..a1d7cf298949c2daf6db77f7d06866d63789c0da Binary files /dev/null and b/yolov5_model/runs/val/many_small_bugs_final/confusion_matrix.png differ diff --git a/yolov5_model/runs/val/many_small_bugs_final/val_batch0_labels.jpg b/yolov5_model/runs/val/many_small_bugs_final/val_batch0_labels.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4756ac7e32d1e11ff4fa677a16c14d8635df347c Binary files /dev/null and b/yolov5_model/runs/val/many_small_bugs_final/val_batch0_labels.jpg differ diff --git a/yolov5_model/runs/val/many_small_bugs_final/val_batch0_pred.jpg b/yolov5_model/runs/val/many_small_bugs_final/val_batch0_pred.jpg new file mode 100644 index 0000000000000000000000000000000000000000..702866a3858c6bc5708154d4cd3da762ad498f02 Binary files /dev/null and b/yolov5_model/runs/val/many_small_bugs_final/val_batch0_pred.jpg differ diff --git a/yolov5_model/runs/val/many_small_bugs_final/val_batch1_labels.jpg b/yolov5_model/runs/val/many_small_bugs_final/val_batch1_labels.jpg new file mode 100644 index 0000000000000000000000000000000000000000..37e5fbf5b21fe644cf43823d10dafef187f65b4f Binary files /dev/null and b/yolov5_model/runs/val/many_small_bugs_final/val_batch1_labels.jpg differ diff --git a/yolov5_model/runs/val/many_small_bugs_final/val_batch1_pred.jpg b/yolov5_model/runs/val/many_small_bugs_final/val_batch1_pred.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3a431b93ddfb00ffd89c02001a10106c736fa373 Binary files /dev/null and b/yolov5_model/runs/val/many_small_bugs_final/val_batch1_pred.jpg differ diff --git a/yolov5_model/runs/val/many_small_bugs_final/val_batch2_labels.jpg b/yolov5_model/runs/val/many_small_bugs_final/val_batch2_labels.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cda5a20630501d3bbd4007cec6ced49aea814571 Binary files /dev/null and b/yolov5_model/runs/val/many_small_bugs_final/val_batch2_labels.jpg differ diff --git a/yolov5_model/runs/val/many_small_bugs_final/val_batch2_pred.jpg b/yolov5_model/runs/val/many_small_bugs_final/val_batch2_pred.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6aeaeb1b75ce3c6318e4bf53f3043ef38ce9d553 Binary files /dev/null and b/yolov5_model/runs/val/many_small_bugs_final/val_batch2_pred.jpg differ