srwi / PyCharm-PixelLens

Free PyCharm image viewer plugin for visualizing and debugging NumPy, OpenCV, PyTorch, TensorFlow, JAX, and PIL data.
https://plugins.jetbrains.com/plugin/25039-pixellens
GNU General Public License v3.0
20 stars 0 forks source link

Error when trying to view image during remote debugging #16

Closed alexx-km closed 2 months ago

alexx-km commented 2 months ago

An exception occurred in the plugin.

Environment:

Exception details:

Error evaluating expression Traceback (most recent call last):
  File "--~--/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 1565, in do_it
    result = pydevd_vars.evaluate_expression(self.thread_id, self.frame_id, self.expression, self.doExec)
  File "--~--/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_vars.py", line 461, in evaluate_expression
    return eval_func(expression, updated_globals, frame, doExec, get_eval_exception_msg)
  File "--~--/.pycharm_helpers/pydevd_asyncio/pydevd_asyncio_utils.py", line 93, in _eval_async_expression
    result = exec_async_code(compiled, global_names)
  File "--~--/.pycharm_helpers/pydevd_asyncio/pydevd_asyncio_utils.py", line 117, in _exec_async_code
    result = func()
  File "<string>", line 3, in <module>
  File "<string>", line 5, in <module>
NameError: name 'img' is not defined
com.jetbrains.python.debugger.pydev.AbstractCommand.processResponse(AbstractCommand.java:235)
com.jetbrains.python.debugger.pydev.EvaluateCommand.processResponse(EvaluateCommand.java:43)
com.jetbrains.python.debugger.pydev.AbstractCommand.execute(AbstractCommand.java:166)
com.jetbrains.python.debugger.pydev.RemoteDebugger.executeCommand(RemoteDebugger.java:791)
com.jetbrains.python.debugger.pydev.RemoteDebugger.evaluate(RemoteDebugger.java:158)
com.jetbrains.python.debugger.pydev.MultiProcessDebugger.evaluate(MultiProcessDebugger.java:200)
com.jetbrains.python.debugger.PyDebugProcess.evaluate(PyDebugProcess.java:807)
com.jetbrains.python.debugger.PyDebugProcess.evaluate(PyDebugProcess.java:803)
com.github.srwi.pixellens.interop.Python.executeStatement(Python.kt:21)
com.github.srwi.pixellens.imageProviders.ImageProvider.prepareData(ImageProvider.kt:59)
com.github.srwi.pixellens.imageProviders.ImageProvider.getImageAndMetadata(ImageProvider.kt:43)
com.github.srwi.pixellens.imageProviders.ImageProvider.getDataByVariableName(ImageProvider.kt:36)
com.github.srwi.pixellens.actions.ViewAsImageAction$actionPerformed$1.run(ViewAsImageAction.kt:28)
com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:477)
com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:133)
com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsynchronously$6(CoreProgressManager.java:528)
com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:250)
com.intellij.openapi.progress.ProgressManager.lambda$runProcess$0(ProgressManager.java:100)
com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:221)
com.intellij.platform.diagnostic.telemetry.helpers.TraceKt.use(trace.kt:46)
com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:220)
com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:660)
com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:659)
com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:79)
com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:202)
com.intellij.openapi.progress.ProgressManager.runProcess(ProgressManager.java:100)
com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$5(ProgressRunner.java:250)
com.intellij.openapi.progress.impl.ProgressRunner$ProgressRunnable.run(ProgressRunner.java:500)
com.intellij.util.concurrency.ChildContext$runAsCoroutine$1.invoke(propagation.kt:81)
com.intellij.util.concurrency.ChildContext$runAsCoroutine$1.invoke(propagation.kt:81)
com.intellij.util.concurrency.ChildContext.runAsCoroutine(propagation.kt:86)
com.intellij.util.concurrency.ChildContext.runAsCoroutine(propagation.kt:81)
com.intellij.openapi.progress.impl.ProgressRunner.lambda$launchTask$18(ProgressRunner.java:466)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
java.base/java.lang.Thread.run(Thread.java:840)

Steps to reproduce:

  1. Start debugging on remote machine
  2. Try to view a tensor image (on GPU, with shape torch.Size([3, 480, 800]))

The first time I tried to view this image it worked, but it was visualized wrong (just six black lines) as it had the shape torch.Size([1, 1, 6, 3, 480, 800]). After I tried to directly access the batch with img[0][0] in "Evaluate Expression", the error occured.

If you have any further questions, please feel free to ask. I'd be glad to help!

srwi commented 2 months ago

Hi @alexx-km, thank you for reporting the issue. I happened to notice the same problem with CHW images yesterday and already submitted a fix to the JetBrains marketplace. If you can't wait for it to be approved, you can already manually install the 0.2.1 update by downloading the artifact here (very bottom of the page) and then following the installation instructions.

Regarding the second issue with viewing slices of a tensor, I can reproduce the problem and will work on a fix soon!

BTW: Sorry about the spam comments. I don't know why they are targeting this repo.

alexx-km commented 2 months ago

Hi @srwi, thank you for the swift reply! Sounds great, I'm looking forward to the fix.

srwi commented 2 months ago

Version 0.2.1 was approved and fixes both the dimension order and slicing problem. Would it be possible for you to confirm that?

alexx-km commented 2 months ago

Just tested the new version and it worked flawlessly. Thank you so much!

alexx-km commented 2 months ago

Hey @srwi , when I try to visualize tensors / numpy arrays on the newest PyCharm version, I get the following error

Environment:

Exception details:

Unexpected JSON token at offset 2304: Expected quotation mark '"', but had 'EOF' instead at path: $.data
JSON input: .....vb2WT729gYICvkwq4b1zoKC70mCFPZ
kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:24)
kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:32)
kotlinx.serialization.json.internal.AbstractJsonLexer.fail(AbstractJsonLexer.kt:580)
kotlinx.serialization.json.internal.AbstractJsonLexer.fail$default(AbstractJsonLexer.kt:578)
kotlinx.serialization.json.internal.AbstractJsonLexer.fail$kotlinx_serialization_json(AbstractJsonLexer.kt:231)
kotlinx.serialization.json.internal.StringJsonLexer.consumeKeyString(StringJsonLexer.kt:95)
kotlinx.serialization.json.internal.AbstractJsonLexer.consumeString(AbstractJsonLexer.kt:365)
kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeString(StreamingJsonDecoder.kt:339)
com.github.srwi.pixellens.data.Base64ByteArraySerializer.deserialize(BatchDataPayload.kt:21)
com.github.srwi.pixellens.data.Base64ByteArraySerializer.deserialize(BatchDataPayload.kt:12)
kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69)
kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43)
kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70)
kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableElement(StreamingJsonDecoder.kt:168)
com.github.srwi.pixellens.data.BatchDataPayload$$serializer.deserialize(BatchDataPayload.kt:26)
com.github.srwi.pixellens.data.BatchDataPayload$$serializer.deserialize(BatchDataPayload.kt:26)
kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69)
kotlinx.serialization.json.Json.decodeFromString(Json.kt:165)
com.github.srwi.pixellens.imageProviders.ImageProvider.getBatchData(ImageProvider.kt:283)
com.github.srwi.pixellens.imageProviders.ImageProvider.getBatchByExpression(ImageProvider.kt:31)
com.github.srwi.pixellens.actions.ViewAsImageAction$actionPerformed$1.run(ViewAsImageAction.kt:28)
com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:477)
com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:133)
com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsynchronously$6(CoreProgressManager.java:528)
com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:249)
com.intellij.openapi.progress.ProgressManager.lambda$runProcess$0(ProgressManager.java:98)
com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:221)
com.intellij.platform.diagnostic.telemetry.helpers.TraceKt.use(trace.kt:49)
com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:220)
com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:660)
com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:659)
com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:79)
com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:202)
com.intellij.openapi.progress.ProgressManager.runProcess(ProgressManager.java:98)
com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$5(ProgressRunner.java:249)
com.intellij.openapi.progress.impl.ProgressRunner$ProgressRunnable.run(ProgressRunner.java:501)
com.intellij.openapi.progress.impl.ProgressRunner.lambda$launchTask$18(ProgressRunner.java:466)
com.intellij.util.concurrency.ChildContext$runAsCoroutine$1.invoke(propagation.kt:92)
com.intellij.util.concurrency.ChildContext$runAsCoroutine$1.invoke(propagation.kt:92)
com.intellij.util.concurrency.ChildContext.runAsCoroutine(propagation.kt:97)
com.intellij.util.concurrency.ChildContext.runAsCoroutine(propagation.kt:92)
com.intellij.openapi.progress.impl.ProgressRunner.lambda$launchTask$19(ProgressRunner.java:464)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:735)
java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:732)
java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:732)
java.base/java.lang.Thread.run(Thread.java:1583)

Do you already know about this issue?

srwi commented 2 months ago

Hi @alexx-km, did it only start with the 2024.2.1 update of PyCharm or with the 0.2.2 update of PixelLens? Does it happen every time or randomly?

Unfortunately I wasn't able to reproduce it yet.

alexx-km commented 2 months ago

I think it started with the update to 2024.2.1 and happens every time I try to open an image using remote (ssh) debugging. Is there any way to furthernhelp you debug this problem?

julien-seitz commented 2 months ago

Have the same problem and it started with 2024.2.1. I went back to 2024.2.0.1 and it worked again. It looks like also another Visualization Plugin (https://plugins.jetbrains.com/plugin/14371-debug-image-viewer-former-opencv-image-viewer-) is affected by the same problem. The Problem was already existing when using Version 0.2.1 of PixelLens

srwi commented 2 months ago

Thanks for the additional information. I'll dig into it further this evening.

srwi commented 2 months ago

It looks like it's this bug in PyCharm: https://youtrack.jetbrains.com/issue/PY-75568/Large-strings-truncated-when-displayed-in-debug-output-or-evaluate-windows-again

I can fix the issue by reducing the data transmission buffer size to 256 bytes (from 2.000.000 bytes) but that significantly slows down the transmission. I'll try to find a more elegant solution. Hopefully they'll fix the bug soon as it's quite a significant one.

srwi commented 2 months ago

I went the easy route and applied that workaround only for the affected PyCharm version. It will be available in 0.2.3 once it's approved, but you should probably just skip the 2024.2.1 entirely until the PyCharm bug is fixed.

Thank you for being so quick about reporting the problem!

julien-seitz commented 2 months ago

also thanks very much for taking care about that problem that quickly ;-)