def saveNtdConfMats(cmRaw, cmCropped, ntdGameInfo, infix=None): fn = "confMats_{}_{}_{}_{}.pkl".format(ntdGameInfo['setID'], ntdGameInfo['repeat'], ntdGameInfo['size'], cfg.uuid) fid = open(iconicImagesFileFormat().format(fn), "wb") pickle.dump({"raw": cmRaw, "cropped": cmCropped}, fid) fid.close()
def loadSvmModel(modelParams, dataType, setID, repeat, size, X_train, y_train): modelFn = modelParams['modelFn'] if modelFn is not None: model = pickle.load(open(modelFn, "rb")) else: model = train_SVM(X_train, y_train) fn = iconicImagesFileFormat().format("model{}_svm_{}_{}_{}.pkl".format( dataType, setID, repeat, size)) pickle.dump(model, open(fn, "wb")) print(" saved model to {}".format(fn)) print("\n\n-=- model loaded -=-\n\n") return model
def saveMat(fn, mat): fid = open(iconicImagesFileFormat().format(fn), "wb") pickle.dump(mat, fid) fid.close()
def loadMat(fn): print(iconicImagesFileFormat().format(fn)) fid = open(iconicImagesFileFormat().format(fn), "rb") mats = pickle.load(fid) fid.close() return mats["raw"], mats["cropped"]
def constructFilenameToSaveImage(setID, repeat, size, name, score): return iconicImagesFileFormat().format("{}_{}_{}_{}_{}.jpg".format( setID, repeat, size, name, score))
def constructFilenameToLoad(setID, repeat, size): return iconicImagesFileFormat().format("{}_{}_{}.txt".format( setID, repeat, size))
train_size = 300 test_size = 300 X_train, X_test, y_train, y_test, X_idx = split_data(train_size, test_size, \ l_feat,l_idx, y,\ clsToSet) print(X_train.shape) print(y_train.shape) if args.model is not None: model = pickle.load(open(args.model,"rb")) else: model = train_SVM(X_train,y_train) pickle.dump(model,open(iconicImagesFileFormat().format("model.pkl"),"wb")) # print("accuracy on test data {}".format(model.score(X_test,y_test))) """ -> below is the raw output for x_test; we want the max "k" values from each dataset (along the columns) from ~1000 images of each dataset -> a good "k" is 10 -> print the image paths to a file -> use the format given below -> TODO: write the "findMaxRegions" function in "hog_svm.py" """ # rawOutputs = np.matmul(model.coef_,npt(X_test)) + model.intercept_[:,np.newaxis] rawOutputs = model.decision_function(X_test)