def write(self, data): """ Write the given data to the database. :type data: dict :rtype: None """ utils.saveJson(self.path(), data)
def main(): src = sys.argv[1] dest = sys.argv[2] stats = utils.loadJson(sys.argv[3]) threshold = float(sys.argv[4]) # keep executing only if stats were loaded if stats != None: stats = stats['classes'] cache = utils.loadJson(getCacheName(stats)) if cache == None: cache = {} applySegmentation(src, dest, threshold, stats, cache) utils.saveJson(cache, getCacheName(stats)) else: print('No stats available, cant process images') print('Finished')
def main(): src = sys.argv[1] dest = sys.argv[2] pixels = {} for f in os.listdir(src): print('Processing ' + f) data = utils.loadJson(src + f) for key in data: if key != 'height' and key != 'width' and len(data[key]) > 0: if not key in pixels: pixels[key] = [] extracted = utils.extractRGB(data[key]) pixels[key] = pixels[key] + extracted for key in pixels: print('Extracted ' + str(len(pixels[key])) + ' pixels for ' + key) print('Saving') utils.saveJson(pixels, dest + 'pixels.json') print('Finished')
def main(): src = sys.argv[1] dest = sys.argv[2] attempts = 10 ratio = 0.5 thres = 0.95 pixels = utils.loadJson(src) bestSamples = {} bestStats = {'classes': []} minVal = [1e10000] minTrain = [] minTest = [] for n in range(attempts): print('** Attempt ' + str(n)) samples = {} stats = {'classes': []} # get sets and stats from data for key in pixels: print('\tProcessing color ' + key) sets = getBestSets(key, pixels[key], ratio, attempts) stats['classes'].append(sets['stats']) samples[key] = sets # calculate the classification error totalTrain = 0.0 totalVal = 0.0 totalTest = 0.0 errTrain = 0 errVal = 0 errTest = 0 cache = {} for key in samples: clsTrain = classify(samples[key]['train'], thres, stats['classes'], cache) errTrain += classificationError(clsTrain, key) totalTrain += len(samples[key]['train'][utils.R]) clsVal = classify(samples[key]['val'], thres, stats['classes'], cache) errVal += classificationError(clsVal, key) totalVal += len(samples[key]['val'][utils.R]) clsTest = classify(samples[key]['test'], thres, stats['classes'], cache) errTest += classificationError(clsTest, key) totalTest += len(samples[key]['test'][utils.R]) print('\tError train: \t' + str(errTrain) + '\t' + str(errTrain / totalTrain)) print('\tError val: \t' + str(errVal) + '\t' + str(errVal / totalVal)) print('\tError test: \t' + str(errTest) + '\t' + str(errTest / totalTest)) if errVal < minVal[0]: minVal = [errVal, totalVal] minTrain = [errTrain, totalTrain] minTest = [errTest, totalTest] bestSamples = samples bestStats = stats if minVal[0] == 0: break print('Min error') print('\ttrain: \t' + str(minTrain[0]) + '\t' + str(minTrain[0] / minTrain[1])) print('\tval: \t' + str(minVal[0]) + '\t' + str(minVal[0] / minVal[1])) print('\ttest: \t' + str(minTest[0]) + '\t' + str(minTest[0] / minTest[1])) bestSamples = {'samples': bestSamples, 'errors': {}} bestSamples['errors']['train'] = minTrain bestSamples['errors']['val'] = minVal bestSamples['errors']['test'] = minTest print('Saving data') utils.saveJson(bestStats, dest + 'learnedStats.json') utils.saveJson(bestSamples, dest + 'learnedSamples.json') print('Finished')
# update current usage book = utils.openGoogleSheet(gSheetId) dataSheet = book.get_worksheet(0) date = dataSheet.acell(DATE_CELL).value cap = int(dataSheet.acell(CAP_CELL).value.split()[0]) target = int(dataSheet.acell(TARGET_CELL).value.split()[0]) usage = int(dataSheet.acell(USAGE_CELL).value.split()[0]) today = int(dataSheet.acell(TODAY_CELL).value.split()[0]) # build data data = { 'date': date, 'cap': cap, 'usage': usage, 'today': today, 'warning': int(target*GRAPH_WARNING), 'error': target, 'gsheet': gSheetUrl } # write cache utils.saveJson(CACHE_USAGE, data) except: data = None # echo print('Content-Type: application/json') print() print(json.dumps(data))
2.2 Gets the locations in which the image has Faces 2.3 Adds the locations in the global JSON_LIST 3. Dumps the JSON_LIST to results.json 4. STOP """ args = parse_args() TestImgsFolder = args.string TestImgs = getImages(TestImgsFolder) for i in range(0, len(TestImgs)): imgtest = cv2.imread(TestImgsFolder + '/' + TestImgs[i]) gray = cv2.cvtColor(imgtest, cv2.COLOR_RGB2GRAY) locations = getFaceLocations(gray) if locations is not None: locations = nonMaximalSupression(np.array(locations), 0.25) addToJson(TestImgs[i], locations) saveJson(JSON_LIST)