question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stuck at ExportByteArray

See original GitHub issue
session=WolframLanguageSession()
img = Image.open("path_to_image")
data = session.evaluate(wl.CurvatureFlowFilter(img, 50))
z = session.evaluate(wl.ExportByteArray(data, "PNG"))

Changing CurvatureFlowFilter to other functions like ‘Binarize’ gives the desired output but gets stuck at ExportByteArray.

This is the Trace when process is manually interrupted:

File “/home/nikhal/.PyCharmCE2019.1/config/scratches/scratch_82.py”, line 25, in Binarize z = session.evaluate(wl.ExportByteArray(data, “PNG”)) File “/usr/local/lib/python3.6/dist-packages/wolframclient/evaluation/kernel/localsession.py”, line 259, in evaluate result = self.evaluate_wrap(expr, **kwargs) File “/usr/local/lib/python3.6/dist-packages/wolframclient/evaluation/kernel/localsession.py”, line 256, in evaluate_wrap return self.evaluate_wrap_future(expr, **kwargs).result() File “/usr/lib/python3.6/concurrent/futures/_base.py”, line 427, in result self._condition.wait(timeout) File “/usr/lib/python3.6/threading.py”, line 295, in wait waiter.acquire() KeyboardInterrupt

Here is my code: binarize.txt

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
DbxDevcommented, May 28, 2019

I suspect that the size of the input image makes a difference here.

I ran your script on a 100kb file (ExampleData[{"TestImage", "House"}]) and it worked. Then I used a bigger one generated with RandomImage[1, {2000, 2000}, ColorSpace -> "RGB"]. This time it took a lot of time to evaluate CurvatureFlowFilter. Log says ~80sec.

To better understand where the bottleneck is, I ran the code in a notebook. With an image of size 200x200 pixels, I already get an evaluation timer of a second:

In[1]:= img = RandomImage[1, {200, 200}, ColorSpace -> "RGB"];

In[2]:= AbsoluteTiming[CurvatureFlowFilter[img, 50];]
Out[2]= {1.14688, Null}

No doubt that it would takes tens of seconds for the bigger picture I mentioned above.

A quick comment, not related, in general one should avoid as much as possible to send data back and forth to the kernel. Remove unnecessary intermediate variables whenever you can.

e.g.: rewriting

    data = session.evaluate(wl.CurvatureFlowFilter(img, 50))
    z = session.evaluate(wl.ExportByteArray(data, "PNG"))

as

z = session.evaluate(
        wl.ExportByteArray(
            wl.CurvatureFlowFilter(img, 50), "PNG"
        ))

reduces the data exchanged to only the resulting byte array. Of course your code is much easier to debug and I understand why you would write it this way until it actually works, so feel free to ignore this.

0reactions
DbxDevcommented, Oct 14, 2019

Closing the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

export byte array to PDF - MSDN - Microsoft
User731351515 posted. Hi All,. I am trying to export a byte array to PDF. I can't find the problem but, I am getting...
Read more >
PythonExpression - Wolfram Language Documentation
"PythonExpression" internally starts and stops a Python session every time ImportString is called, which takes a substantial amount of time: Copy to clipboard....
Read more >
Java File Transfer getting stuck halfway - Stack Overflow
I am trying to send a file (an image sent as a byte array) with the client and then the server should receive...
Read more >
Diff - gerrit - Google Git
... supporter backdrop door scenery open closed locked inside gender is are say ... Export ExportAutoReplacements ExportByteArray ExportForm ExportPacket ...
Read more >
dl4 call pgmg guide 001203 - Unibasic
If the insertion is successful, the table is locked and a pointer to first item (not item ... ExportBYTEArray - Store BYTE array...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found