def run(self): print "Preparing the environment" self.prepareEnvironment() print "Reading in the training data" imageCollections = data_io.get_train_df() wndchrmWorker = WndchrmWorkerTrain() print "Getting features" if not self.loadWndchrm: #Last wndchrm set of features featureGetter = FeatureGetter() fileName = data_io.get_savez_name() if not self.load: #Last features calculated from candidates (namesObservations, coordinates, train) = Utils.calculateFeatures(fileName, featureGetter, imageCollections) else: (namesObservations, coordinates, train) = Utils.loadFeatures(fileName) print "Getting target vector" (indexes, target, obs) = featureGetter.getTargetVector(coordinates, namesObservations, train) print "Saving images" imageSaver = ImageSaver(coordinates[indexes], namesObservations[indexes], imageCollections, featureGetter.patchSize, target[indexes]) imageSaver.saveImages() print "Executing wndchrm algorithm and extracting features" (train, target) = wndchrmWorker.executeWndchrm() else: (train, target) = wndchrmWorker.loadWndchrmFeatures() print "Training the model" model = RandomForestClassifier(n_estimators=500, verbose=2, n_jobs=1, min_samples_split=30, random_state=1, compute_importances=True) model.fit(train, target) print model.feature_importances_ print "Saving the classifier" data_io.save_model(model)
def start(self): # Do not change width = 352 height = 352 # output to capture image output = np.empty((height, width, 3), dtype=np.uint8) # Init camera camera = Camera(width, height) # Init image saver imageSaver = ImageSaver() # Init model model = self.getModel() # Init notificator notificator = Notificator() # Start predicting tempCount = 1 while True: #print("Step...") #start = time.time() # Capture image to output camera.capture(output) imageToCrop = Image.fromarray(output) image = self.cropImage(imageToCrop, 110, 87, 224) tempName = 'temp{}.jpg'.format(tempCount) image.save(tempName) tempCount += 1 if tempCount > Notificator.PREDICTIONS_LENGTH: tempCount = 1 # Predict prediction = model.predict(imagePath=tempName) # Save image to disk with label and probability imageSaver.save(image, prediction) # Manage Notification notificator.manageNotification(prediction) #print("Step took {} seconds".format(time.time()-start)) camera.close()
def run(self): print "Preparing the environment" self.prepareEnvironment() print "Loading the classifier" classifier = data_io.load_model() imageCollections = data_io.get_valid_df() featureGetter = FeatureGetter() wndchrmWorker = WndchrmWorkerPredict() print "Getting the features" if not self.loadWndchrm: #Last wndchrm set of features fileName = data_io.get_savez_name_test() if not self.load: #Last features calculated from candidates (namesObservations, coordinates, _) = Utils.calculateFeatures(fileName, featureGetter, imageCollections) else: (namesObservations, coordinates, _) = Utils.loadFeatures(fileName) print "Saving images" imageSaver = ImageSaver(coordinates, namesObservations, imageCollections, featureGetter.patchSize) imageSaver.saveImages() print "Executing wndchrm algorithm" valid = wndchrmWorker.executeWndchrm(namesObservations) else: (valid, namesObservations) = wndchrmWorker.loadWndchrmFeatures() print "Making predictions" predictions = classifier.predict(valid) predictions = predictions.reshape(len(predictions), 1) print "Writing predictions to file" data_io.write_submission(namesObservations, coordinates, predictions) data_io.write_submission_nice(namesObservations, coordinates, predictions) print "Calculating final results" return Predictor.finalResults(namesObservations, predictions, coordinates)
from MainCrawler import MainCrawler from CakeCrawler import CakeCrawler from XlsWrite import XlsWrite from ImageSaver import ImageSaver m = MainCrawler() print "Crawling main page..." m.crawl() c = CakeCrawler(m.cake_list) print "Crawling cake pages..." c.crawl() x = XlsWrite(c.cake_list) print "Writing Excel sheet..." x.populate_excel() i = ImageSaver(c.cake_list) print "Saving cake images..." i.save_images()