Commit 8fa60a2c authored by josh's avatar josh
Browse files

clean up/sanity check

parent b940e55f
......@@ -88,11 +88,98 @@ class HDRDatabaseInterface(ABC):
def getMSLabelArray(self, imageId: str) -> np.array:
'''
Returns the Mean Shift Segmentation label array as a numpy array
'''
raise NotImplementedError("getMSLabelArray: Method Not Implemented")
def saveMask(self, sliceId: str, maskImage: Image.Image, maskName: str="Mask"):
'''
Saves a mask image associated with a slice
'''
raise NotImplementedError("saveMask: Method Not Implemented")
def importAndProcessImage(self, imagePath: str):
'''
Imports an image from a path into the database and preforms all preprocessing
'''
raise NotImplementedError("importAndProcessImage: Method Not Implemented")
def getModelList(self, imageId, size):
'''
Should return a list of available models
i.e.
[
{
"id" : id,
"name": name
}
]
'''
raise NotImplementedError("getModelList: Method Not Implemented")
def createModel(self, imageId, size, modelName):
'''
Should create and save a model to the database
'''
raise NotImplementedError("createModel: Method Not Implemented")
def getMaskList(self, imageId, size):
'''
Should return a list of available masks for a given slice
i.e.
[
{
"id" : id,
"name": name
}
]
'''
raise NotImplementedError("getMaskList: Method Not Implemented")
# NOTE: DOESN'T COPY DUPLICATES
def saveSamplesTemp(self, modelId, sliceSize, sampleIds):
'''
Should save desired samples and corresponding masks to a temporary directory.
Return the path to the directory
|-- Temp
| |-- 0-sample
| | |-- input.jpg
| | |-- mask.jpg
'''
raise NotImplementedError("saveSamplesTemp: Method Not Implemented")
def saveSlicesForPrediction(self, modelId, sliceSize, sliceIds):
'''
Should create a temporary directory to save slices to.
Return path to temporary dir.
|-- Temp
| |-- img-0.jpg
| |-- img-1.jpg
'''
raise NotImplementedError("saveSlicesForPrediction: Method Not Implemented")
def getModel(self, modelId):
'''
Should load and return a model from the database
'''
raise NotImplementedError("getModel: Method Not Implemented")
def updateModel(self, modelId, model):
'''
Should replace model in the databse with a new model
'''
raise NotImplementedError("updateModel: Method Not Implemented")
class HDRFileDB(HDRDatabaseInterface):
......@@ -206,7 +293,7 @@ class HDRFileDB(HDRDatabaseInterface):
return np.load(msLabelsPath)
def saveMask(self, sliceId: str, maskImage: Image.Image, maskName: str="Mask"):
def saveMask(self, sliceId: str, maskImage: Image.Image, maskName: str="Mask") -> None:
maskName = maskName.replace("-", "_")
baseDir = self._idToBasePath(sliceId)
# Find slice directory with id
......@@ -249,7 +336,7 @@ class HDRFileDB(HDRDatabaseInterface):
MODEL METHODS
'''
def getModelList(self, imageId, size):
def getModelList(self, imageId: str, size: int) -> list:
modelList = []
......@@ -263,7 +350,7 @@ class HDRFileDB(HDRDatabaseInterface):
return modelList
def createModel(self, imageId, size, modelName):
def createModel(self, imageId: str, size: int, modelName: str) -> None:
baseDir = self._idToBasePath(imageId)
modelsDir = baseDir.joinpath(self.MODELS_FOLDER)
......@@ -273,7 +360,7 @@ class HDRFileDB(HDRDatabaseInterface):
hdrModel.save(saveDir)
def getMaskList(self, imageId, size):
def getMaskList(self, imageId: str, size: int) -> list:
maskList = []
......@@ -298,7 +385,7 @@ class HDRFileDB(HDRDatabaseInterface):
# NOTE: DOESN'T COPY DUPLICATES
def saveSamplesTemp(self, modelId, sliceSize, sampleIds):
def saveSamplesTemp(self, modelId: str, size: int, sampleIds: list) -> Path:
baseDir = self._idToBasePath(modelId)
modelDir = baseDir.joinpath(self.MODELS_FOLDER).joinpath(modelId.split("-")[-1])
......@@ -307,10 +394,10 @@ class HDRFileDB(HDRDatabaseInterface):
os.mkdir(tempTrainDir)
# Get all mask ids in db
maskIds = [mask["id"] for mask in self.getMaskList(baseDir.name, sliceSize)]
maskIds = [mask["id"] for mask in self.getMaskList(baseDir.name, str(size))]
idParts = self._idParts(modelId)
sliceDir = baseDir.joinpath(self.SLICE_FOLDER).joinpath(sliceSize)
sliceDir = baseDir.joinpath(self.SLICE_FOLDER).joinpath(str(size))
sampleIds = json.loads(sampleIds)
......@@ -332,7 +419,7 @@ class HDRFileDB(HDRDatabaseInterface):
return tempTrainDir
def saveSlicesForPrediction(self, modelId, sliceSize, sliceIds):
def saveSlicesForPrediction(self, modelId: str, size: int, sliceIds: list) -> Path:
baseDir = self._idToBasePath(modelId)
modelDir = baseDir.joinpath(self.MODELS_FOLDER).joinpath(modelId.split("-")[-1])
# Create create new folder to hold slices
......@@ -352,13 +439,13 @@ class HDRFileDB(HDRDatabaseInterface):
return predDir
def getModel(self, modelId):
def getModel(self, modelId: str) -> HDRModel:
baseDir = self._idToBasePath(modelId)
modelDir = baseDir.joinpath(self.MODELS_FOLDER).joinpath(modelId.split("-")[-1])
return HDRModel(loadDir=modelDir)
def updateModel(self, modelId, model):
def updateModel(self, modelId: str, model: HDRModel) -> None:
baseDir = self._idToBasePath(modelId)
modelDir = baseDir.joinpath(self.MODELS_FOLDER).joinpath(modelId.split("-")[-1])
# Remove old model and save new
......@@ -415,6 +502,6 @@ class HDRFileDB(HDRDatabaseInterface):
def _idToBasePath(self, imageId: str) -> Path:
return self.imagesPath.joinpath("{}-{}-{}-{}".format(self._idUid(imageId),
self._idImageExt(imageId),
self._idName(imageId),
"OR"))
\ No newline at end of file
self._idImageExt(imageId),
self._idName(imageId),
"OR"))
\ No newline at end of file
......@@ -16,6 +16,7 @@ import base64
from celery import Celery
def make_celery(app):
celery = Celery(
app.import_name,
......@@ -31,6 +32,7 @@ def make_celery(app):
celery.Task = ContextTask
return celery
'''
Global Variables
......@@ -91,7 +93,6 @@ def getSamples(dataDir: Path) -> [(np.array, np.array)]:
return (np.array(X_TRAIN), np.array(Y_TRAIN))
@celery.task(name="app.trainModelTask")
def trainModelTask(modelId, sliceSize, sampleIds):
# Copy slices and masks to temp folder
......@@ -109,6 +110,7 @@ def trainModelTask(modelId, sliceSize, sampleIds):
return "OK"
@celery.task(name="app.predictModelTask")
def predictModelTask(modelId, sliceSize, sliceIds):
# Copy slices and masks to temp folder
......@@ -126,6 +128,7 @@ def predictModelTask(modelId, sliceSize, sliceIds):
return "OK"
'''
App Routes
'''
......@@ -134,9 +137,11 @@ App Routes
def index():
return render_template("index.html")
'''
DATA DISPLAY
'''
@app.route("/image-select")
def imageSelect():
'''
......@@ -213,10 +218,8 @@ def createNewModel(imageId, size, modelName):
@app.route("/manage-model/<string:imageId>/<string:modelId>/<int:size>")
def manageModel(imageId, modelId, size):
print("managing model:", modelId)
availableMasks = imageDB.getMaskList(imageId, str(size))
sliceList = imageDB.getSliceList(imageId, str(size))
print(availableMasks)
sliceList = imageDB.getSliceList(imageId, str(size))
return render_template("manageModel.html",
imageId=imageId,
sliceSize=size,
......@@ -227,24 +230,17 @@ def manageModel(imageId, modelId, size):
@app.route("/train-model/<string:modelId>/<string:sliceSize>", methods=["POST"])
def trainModel(modelId, sliceSize):
print(modelId)
if request.method == "POST":
print("=========================")
maskIds = request.form["maskIds"]
print(type(maskIds))
result = trainModelTask.delay(modelId, sliceSize, maskIds)
trainModelTask.delay(modelId, sliceSize, maskIds)
return "OK"
@app.route("/predict-model/<string:modelId>/<string:sliceSize>", methods=["POST"])
def predictModel(modelId, sliceSize):
print(modelId)
if request.method == "POST":
print("=========================")
sliceIds = request.form["sliceIds"]
print(sliceIds)
predictModelTask.delay(modelId, sliceSize, sliceIds)
#result = trainModelTask.delay(modelId, sliceSize, maskIds)
return "OK"
'''
......@@ -286,14 +282,13 @@ def uploadImage():
@app.route("/save-mask", methods=["POST"])
def saveMask():
imageId = request.values["imageId"]
sliceId = request.values["sliceId"]
maskName = request.values["maskName"]
imageId = request.values["imageId"]
sliceId = request.values["sliceId"]
maskName = request.values["maskName"]
maskBase64 = request.values["maskBase64"].split(',')[1]
maskImage = Image.open(io.BytesIO(base64.b64decode(maskBase64)))
maskImage = maskImage.convert("RGB")
print("TTESSSSTTT")
np.array(maskImage).shape
imageDB.saveMask(sliceId, maskImage, maskName=maskName)
......
.main-section-container {
width: 100%;
height: 100%;
......
.upload-file-container {
width: 30%;
height: 30%;
......
.main-section-container{
width: 100%;
height: 100%;
......
.main-section-container{
width: 100%;
height: 100%;
......
/*
* Handles event onchange for id: #processed-images
*/
......
......@@ -120,9 +120,9 @@ function loadMaskCanvas() {
// ==================== CREATEM MODEL BUTTON
function createModel(imageId, sliceSize) {
var modelName = prompt("Give Model a Name:", "");
}
// /function createModel(imageId, sliceSize) {
// / var modelName = prompt("Give Model a Name:", "");
// /}
window.addEventListener("load", (event) => {
......
......@@ -16,7 +16,6 @@ function appendToSelect(selectElement, inputId, inputName) {
}
function getRadioValAndName(radioNodeList) {
var val, name;
// get list of radio buttons with specified name
......@@ -33,6 +32,7 @@ function getRadioValAndName(radioNodeList) {
return [val, name]; // return value of checked radio or undefined if none checked
}
/*
* Add sample to batch to use for training
*/
......@@ -62,7 +62,6 @@ function trainModel(modelId, sliceSize, name) {
}
function addSlice(name) {
var selectedReturn = getRadioValAndName(document.getElementsByName(name));
id = selectedReturn[0];
......
/*
* Send request to backend to create a new model for selected image and size
*/
function createNewModel(imageId, size) {
var modelName = prompt("Enter a model name", "");
modelName = modelName.replace(/\s/g, "-")
modelName = modelName.replace(/\s/g, "-")
if (modelName != null && modelName != "") {
$.post(`/create-new-model/${imageId}/${size}/${modelName}`, function(data) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment