Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fixes for Interactive Classifier and Non-Interactive Classifier #4

Merged
merged 7 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ RUN apt-get install -y \
python3-distutils

# Build Gamera 4.
RUN git clone https://github.com/DDMAL/gamera4-rodan.git
WORKDIR /gamera4-rodan
#RUN git clone https://github.com/DDMAL/gamera4-rodan.git
COPY . /gamera4-rodan
#WORKDIR /gamera4-rodan
#this commit fixes miyao staff finder
RUN git checkout 76608f6
#RUN git checkout 76608f6
WORKDIR /gamera4-rodan/gamera-4
RUN python3 setup.py --nowx build
# We need to install Gamera (even though it won't be used)
Expand Down
4 changes: 4 additions & 0 deletions gamera-4/gamera/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ def classify_manual(self, id_name):
A value in range (0, 1), where 0 is uncertain and 1 is certain.
*class_name*
A ``.``-delimited class name."""
if type(id_name) is bytes:
id_name = id_name.decode()
if util.is_string_or_unicode(id_name):
id_name = [(1.0, id_name)]
elif type(id_name) is not list:
Expand Down Expand Up @@ -383,6 +385,8 @@ def classify_automatic(self, id_name):
A value in range (0, 1), where 0 is uncertain and 1 is certain.
*class_name*
A ``.``-delimited class name."""
if type(id_name) is bytes:
id_name = id_name.decode()
if util.is_string_or_unicode(id_name):
id_name = [(0.0, id_name)]
elif not isinstance(id_name, list):
Expand Down
15 changes: 11 additions & 4 deletions gamera-4/include/knnmodule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,17 @@ inline int image_get_id_name(PyObject* image, char** id_name, int* len) {
PyErr_SetString(PyExc_TypeError, "knn: could not get string from id_name tuple.");
return -1;
}
Py_ssize_t lenTmp = 0;
if(PyBytes_AsStringAndSize(id, id_name, &lenTmp) < 0){
PyErr_SetString(PyExc_TypeError, "knn: could not get string from id_name tuple.");
return -1;
PyObject *id_bytes = id;
PyTypeObject* type = Py_TYPE(id);
const char* typeName = type->tp_name;
if(PyUnicode_Check(id)) {
const char *id_str = PyUnicode_AsUTF8(id); //id is currently the class name, type PyUnicode (str)
id_bytes = PyBytes_FromString(id_str);
}
Py_ssize_t lenTmp = 0;
if (PyBytes_AsStringAndSize(id_bytes, id_name, &lenTmp) < 0){
PyErr_SetString(PyExc_TypeError, "knn: could not get string from id_name tuple.");
return -1;
}
*len = lenTmp;
if (*id_name == nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion gamera-4/src/knncore/knncoremodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ static PyObject* knn_classify_with_images(PyObject* self, PyObject* args) {
(This is most likely because features have not been generated.)");
return 0;
}

//id_name is equivalent to class_name in glyph (RODAN Comment)
char* id_name;
int len;
if (image_get_id_name(cur, &id_name, &len) < 0) {
Expand Down