interactive-deep-colorization
interactive-deep-colorization copied to clipboard
Unicode String and Integer Division related crashes (python2 vs. python3)
My attempted command is python3 ideepcolor.py --cpu_mode
All dependencies seem to have installed correctly.
I am obtaining the following crash on Intel i3 w/ Debian 9 Codename Stretch:
b'test_imgs/mortar_pestle.jpg'
Traceback (most recent call last):
File "ideepcolor.py", line 60, in <module>
window = gui_design.GUIDesign(color_model=colorModel, dist_model=distModel, img_file=args.image_file, load_size=args.load_size, win_size=args.win_size)
File "/home/bb/ideepcolor/ui/gui_design.py", line 112, in __init__
self.drawWidget.init_result(img_file)
File "/home/bb/ideepcolor/ui/gui_draw.py", line 54, in init_result
self.read_image(image_file.encode('utf-8')) # read an image
File "/home/bb/ideepcolor/ui/gui_draw.py", line 79, in read_image
im_bgr = cv2.imread(image_file)
TypeError: bad argument type for built-in operation
Thanks for your help.
It seems that opencv doesn't work on your machine. You could print the image_file. You can also write a simple test script to test the OpenCV.
import cv2
im_bgr = cv2.imread(your_image_file)
Test script above with valid image file exits quietly without error.
hmmm... maybe removing the .encode('utf-8'). also print out the image_file in the gui_draw.py,
Ok, removing .encode('utf-8') I believe the image loads and the program goes to the next step. I guess I have to wait for a long time for the giu to show up? (Yes after a wait the gui has showed up with the mortar and pestle)
test_imgs/mortar_pestle.jpg
scale = 2.000000
Now that I've got the gui up and running, am now getting this error when clicking on the Load button:
Traceback (most recent call last):
File "/home/bb/ideepcolor/ui/gui_design.py", line 151, in load
self.drawWidget.load_image()
File "/home/bb/ideepcolor/ui/gui_draw.py", line 227, in load_image
img_path = unicode(QFileDialog.getOpenFileName(self, 'load an input image'))
NameError: name 'unicode' is not defined
Removing the unicode() makes it work ok...
Getting into using the program, I noticed creating a point then assigning a color gives this error. Cannot change to any color, the points always stay gray.
Traceback (most recent call last):
File "/home/bb/ideepcolor/ui/gui_palette.py", line 80, in mousePressEvent
self.update_ui(color_id)
File "/home/bb/ideepcolor/ui/gui_palette.py", line 73, in update_ui
color = self.colors[color_id]
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
Haven't seen that before. Maybe you would like to print out the color_id variable.
@junyanz When I print the variable at that point in gui_palette.py it reports 4.0 (when I click on the 4th color in the palette). Choosing colors using the gamut seems to work fine. So self.colors is expecting to hear something like 4, but is getting 4.0 obviously not an integer. So when sending to color, I had to change to
color = self.colors[int(color_id)]
and it works.
So far this is what I've done to get things to work (python3/debian9):
$ git diff
diff --git a/ideepcolor.py b/ideepcolor.py
index 81aff2b..5e6102a 100644
--- a/ideepcolor.py
+++ b/ideepcolor.py
@@ -57,8 +57,7 @@ if __name__ == '__main__':
# initialize application
app = QApplication(sys.argv)
- window = gui_design.GUIDesign(color_model=colorModel, dist_model=distModel,
- img_file=args.image_file, load_size=args.load_size, win_size=args.win_size)
+ window = gui_design.GUIDesign(color_model=colorModel, dist_model=distModel, img_file=args.image_file, load_size=args.load_size, win_size=args.win_size)
app.setStyleSheet(qdarkstyle.load_stylesheet(pyside=False)) # comment this if you do not like dark stylesheet
app.setWindowIcon(QIcon('imgs/logo.png')) # load logo
window.setWindowTitle('iColor')
diff --git a/ui/gui_draw.py b/ui/gui_draw.py
index 6e2abae..7b8dcde 100644
--- a/ui/gui_draw.py
+++ b/ui/gui_draw.py
@@ -51,7 +51,8 @@ class GUIDraw(QWidget):
self.update()
def init_result(self, image_file):
- self.read_image(image_file.encode('utf-8')) # read an image
+ print(image_file)
+ self.read_image(image_file) # read an image
self.reset()
def get_batches(self, img_dir):
@@ -223,7 +224,7 @@ class GUIDraw(QWidget):
self.eraseMode = not self.eraseMode
def load_image(self):
- img_path = unicode(QFileDialog.getOpenFileName(self, 'load an input image'))
+ img_path = QFileDialog.getOpenFileName(self, 'load an input image')
self.init_result(img_path)
def save_result(self):
diff --git a/ui/gui_palette.py b/ui/gui_palette.py
index 9d14030..b7fa908 100644
--- a/ui/gui_palette.py
+++ b/ui/gui_palette.py
@@ -68,9 +68,10 @@ class GUIPalette(QWidget):
def update_ui(self, color_id):
self.color_id = color_id
+ print(color_id)
self.update()
if color_id >= 0:
- color = self.colors[color_id]
+ color = self.colors[int(color_id)]
self.emit(SIGNAL('update_color'), color)
self.update()
Also note now that I've rebuilt caffe with openmp things are running faster. 👍
Thanks for the update. I fixed the integer division issue with the latest commit.
Awesome, color palettes are working now. Issue remains with Unicode strings. I wonder if that's because python3 strings work different than python2?
probably. It was introduced by this PR.
I see https://github.com/junyanz/interactive-deep-colorization/blame/python3/ui/gui_draw.py
Strings are already unicode in python3 whereas python2 is old-fashioned ASCII, requiring conversion.
You may want a python3 branch. https://github.com/Benitoite/interactive-deep-colorization/tree/python3
Perhaps a python2/python3 conditional is possible.
I think sometimes people's OS/distribution will allow either one or both pythons, sometimes because of package managers or a dependencies python hook locked to one version.