def runTest(): global model aug = Augmentation.Augmentation(sys.argv[2]) data_transforms = aug.applyTransforms() imageLink = request.form['link'] timestr = ''.join(random.choice(string.lowercase) for x in range(8)) dst = "static/augdata/" + timestr + '.jpg' float_formatter = lambda x: "\t %.3f" % x try: urllib.urlretrieve(imageLink, dst) except: print('Cannot find %s' % (dst)) return render_template('index.html') #time.sleep(3); #model = torch.load("/home/koustav/Desktop/IPA/intelligent_photograph_assesment/CNN/models/net_DenseNet161_crop_True_lr_0.001.model"); t = TestModule.TestModule(model, data_transforms['val'], '', '', '', '') namevaluepairs = t.PredictSortedLabels(dst) for count, (style, prob) in enumerate(namevaluepairs): namevaluepairs[count] = (style, float_formatter(prob)) #styleandvalues = "\n".join('{}: {}'.format(val,key) for key, val in namevaluepairs.items()) return render_template('index.html', testImageName=dst, styleLabels=namevaluepairs)
print('Loading CNN from %s' % (model_path)) model_ft = torch.load(model_path) print('Training Started...') train_model(model_ft, criterion, optimizer_ft, scheduler_ft, num_epochs=args.epochs) #Testing if args.withTesting: DAug = ag.Augmentation(args.aug_test) data_transforms = DAug.applyTransforms() t = TestModule.TestModule(model_ft, data_transforms['val'], args.testDataPath, args.testLabels, args.testIds, args.fiftyPatch) CM, AP, mAP_macro, mAP_weighted, mAP_micro, PerClassP = t.MAPTracker() printed_results = '\n'.join([ "AP : " + str(AP), "MAP_MACRO : " + str(mAP_macro), "MAP_MICRO : " + str(mAP_micro), "MAP_WEIGHTED : " + str(mAP_weighted) ]) PCP = '\n'.join([ cname + ':' + str(pcp) for cname, pcp in zip(dset_classes, PerClassP.tolist()) ]) #print ("\nAP = %f \nmAP_macro = %f \nmAP_weighted = %f \nmAP_micro = %f \n"%(AP,mAP_macro,mAP_weighted,mAP_micro)); print("\nPrecision\n######################") print(colored(printed_results, 'white'))