diff --git a/dataset/dji_roco/robomaster_Final Tournament/image/desktop.ini b/dataset/dji_roco/robomaster_Final Tournament/image/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..6e6d9b27d5f2752c3d0980b29497a3fa73efadd7 --- /dev/null +++ b/dataset/dji_roco/robomaster_Final Tournament/image/desktop.ini @@ -0,0 +1,3 @@ +[LocalizedFileNames] +VW_CH3IRobotVsEvolution_BO2_2_10.jpg=@VW_CH3IRobotVsEvolution_BO2_2_10.jpg,0 +VW_CH3IRobotVsEvolution_BO2_2_9.jpg=@VW_CH3IRobotVsEvolution_BO2_2_9.jpg,0 diff --git a/dataset/dji_roco/robomaster_Final Tournament/image_annotation/desktop.ini b/dataset/dji_roco/robomaster_Final Tournament/image_annotation/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..209520bac2150516db3db2fe06f869b1520208c3 --- /dev/null +++ b/dataset/dji_roco/robomaster_Final Tournament/image_annotation/desktop.ini @@ -0,0 +1,2 @@ +[LocalizedFileNames] +VW_CH3IRobotVsEvolution_BO2_2_9.xml=@VW_CH3IRobotVsEvolution_BO2_2_9.xml,0 diff --git a/robots-at-robots/research/armor_digit/baseline_experiments.py b/robots-at-robots/research/armor_digit/baseline_experiments.py index 23d89d1f3e401b4e3a3e0085e33051524173a6dc..0b7c979881f725679f8d5cfb7ce62f308b6897de 100644 --- a/robots-at-robots/research/armor_digit/baseline_experiments.py +++ b/robots-at-robots/research/armor_digit/baseline_experiments.py @@ -10,7 +10,8 @@ from sklearn.model_selection import train_test_split IMG_SIZE = 28 TEST_SIZE_FACTOR = 0.1 -N_CLASSES = 10 +# TODO maybe use an ENUM (here and armor_dataset_factory) because no 6 makes lost space in array of classes +N_CLASSES = 9 # there is no 6s or 9s # from polystar.common.image_pipeline.image_pipeline import ImagePipeline @@ -34,9 +35,8 @@ N_CLASSES = 10 def load_digits_img_to_data(): # TODO add a model for digits_img in common/polystar/common/models - # TODO add a digits_img in roco_dataset # TODO create a from_dataset (see armor_dataset_factory) to read digits_img from digits_found folder - # TODO change the way to append digit label to label_train and label_test (with the info from model and dataset) + # TODO maybe use an ENUM for labels (here and armor_dataset_factory) because no 6 makes lost space in classes' array # TODO but before, we use this hardcoded path... path = '.\\..\\..\\..\\dataset\\dji_roco\\robomaster_Final Tournament\\digits_found' digits_found = os.listdir(path) @@ -60,7 +60,7 @@ def load_digits_img_to_data(): def training_model(features_train, labels_train, features_test, labels_test): # Source: https://www.sitepoint.com/keras-digit-recognition-tutorial/ - # Cleaning + # Formatting features_train = features_train.reshape(features_train.shape[0], IMG_SIZE, IMG_SIZE, 1) features_test = features_test.reshape(features_test.shape[0], IMG_SIZE, IMG_SIZE, 1) label_train = to_categorical(labels_train, N_CLASSES) @@ -73,12 +73,12 @@ def training_model(features_train, labels_train, features_test, labels_test): input_shape=(IMG_SIZE, IMG_SIZE, 1))) model.add(Conv2D(64, (3, 3), activation='relu')) model.add(MaxPooling2D(pool_size=(2, 2))) - # TODO maybe dont drop or less if not enough data in dataset - # model.add(Dropout(0.25)) + # randomly drop units to avoid overfitting + model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(128, activation='relu')) - # TODO maybe dont drop or less if not enough data in dataset - # model.add((Dropout(0.5))) + # randomly drop units to avoid overfitting + model.add((Dropout(0.5))) # because we have a number of pre-decided classes model.add(Dense(N_CLASSES, activation='softmax')) @@ -88,7 +88,7 @@ def training_model(features_train, labels_train, features_test, labels_test): metrics=['accuracy']) batch_size = 128 - epochs = 10 + epochs = 20 model.fit(features_train, label_train, batch_size=batch_size, @@ -98,13 +98,11 @@ def training_model(features_train, labels_train, features_test, labels_test): score = model.evaluate(features_test, label_test, verbose=0) print('Test loss:', score[0]) print('Test accuracy:', score[1]) - model.save("test_model.h5") + model.save("test_model.h5") # TODO change resulting file name (and erase file test_model.h5) if __name__ == "__main__": digits_features_train, digits_labels_train, digits_features_test, digits_labels_test = load_digits_img_to_data() - for img in digits_labels_train: - print('train', img) for img in digits_labels_test: print('test', img) - # training_model(digits_features_train, digits_labels_train, digits_features_test, digits_labels_test) + training_model(digits_features_train, digits_labels_train, digits_features_test, digits_labels_test) diff --git a/robots-at-robots/research/armor_digit/test_model.h5 b/robots-at-robots/research/armor_digit/test_model.h5 new file mode 100644 index 0000000000000000000000000000000000000000..ab1a911f7af581ed58f33b67e214745ecce8b546 Binary files /dev/null and b/robots-at-robots/research/armor_digit/test_model.h5 differ diff --git a/robots-at-robots/research/dataset/armor_dataset_factory.py b/robots-at-robots/research/dataset/armor_dataset_factory.py index 8d85045acf09d99ce326ff2b19e07539cf3d3642..75688971c9851a5dd321374a8491e1f69154576a 100644 --- a/robots-at-robots/research/dataset/armor_dataset_factory.py +++ b/robots-at-robots/research/dataset/armor_dataset_factory.py @@ -1,5 +1,6 @@ from pathlib import Path from typing import List, Iterable, Tuple +import cv2 import matplotlib.pyplot as plt @@ -32,13 +33,17 @@ class ArmorDatasetFactory: def save_digits_img(): for j, (digit_img, c, n, k, p) in enumerate(ArmorDatasetFactory.from_dataset(DJIROCODataset.Final)): # we ignore the 6s, because the format of their pictures is not accurate and we don't need them - if n != 6: - if j >= 50: - break - print(c, n, k, 'in', p) - plt.imshow(digit_img) - plt.savefig(str(p.parents[1]) + '\\digits_found\\digit' + str(j) + '_' + c.name + '_' + str(n) + '.png') - plt.clf() + if n != 6 and j >= 5925: # TODO change j value depending where you are in saving (to save time) + # if j >= 50: + # break + try: + print(c, n, k, 'in', p) + plt.imshow(digit_img) + plt.savefig(str(p.parents[1]) + '\\digits_found\\digit' + str(j) + '_' + c.name + '_' + str(n) + '.png') + plt.clf() + except ValueError: + # because some digit's pictures have zero-array values + continue if __name__ == "__main__":