2
$\begingroup$

over the last few weeks I routinely deployed neural nets to the cloud for computation. Today, even the simplest example does not work anymore:

(*initialise random neural net that talkes 200x200 image as input*)
scrnet = NetInitialize@
  NetChain[{ConvolutionLayer[1, 1], PartLayer[1]}, 
   "Input" -> {1, 200, 200}]

(*Deploy to cloud*)
cnet = CloudExport[scrnet, "MX", Permissions -> "Public"];

(*test on example image *WORKS**)
img = Import["ExampleData/ocelot.jpg"];
With[{net = CloudImport@cnet}, Image@net@{ImageData@img}]

(*Deploy as cloud form page *)
CloudDeploy[
 FormPage[{"image" -> "Image"}, 
  With[{net = CloudImport@cnet}, Image@net@{ImageData@#image}] &], 
 Permissions -> "Public"]

The last piece of code generates a cloud object. If I try to upload the ocelot image I get Image[Failed] as the sole output. If I do not use a net the form works fine:

CloudDeploy[FormPage[{"image" -> "Image"}, Image@ImageData@#image &], 
   Permissions -> "Public"]

Should I contact wolfram support or am I doing something wrong? I have ~1000 cloud credits left on a free account so that should not be the issue.

EDIT: Could it be related to my licence? I am on the free plan for the development platform which claims that "some" functions are restricted.

Best, Max

$\endgroup$
  • $\begingroup$ Huh. I'm not aware of any issue like this. A simple non-image Netchain works fine. ``` scrnet = NetInitialize@NetChain[{ElementwiseLayer[Ramp]}]; cnet = CloudExport[scrnet, "MX", Permissions -> "Public"]; FormPage["nums" -> DelimitedSequence["Real"], With[{net = CloudImport@cnet}, {net@#nums, #nums} &]] ``` when you supply it with input like "1,0,2" $\endgroup$ – Searke Jul 13 '18 at 20:05
  • $\begingroup$ Also, this NetChain seems to work fine in a notebook on Mathematica Online, so it's probably not some kind of strange compatibility issue. You've got me stumped. I guess I should try to capture what errors are happening $\endgroup$ – Searke Jul 13 '18 at 20:12
  • $\begingroup$ You mean you can ClodDeploy[] the conv net from mathematica online but not from the desktop version? $\endgroup$ – MaxJ Jul 16 '18 at 6:43
  • $\begingroup$ No. The Netchain works both in Desktop Mathematica and in a notebook on Mathematica Online. So it's pretty mysterious to me why it's returning $Failed. I'm asking around and filing a bug report, but you might want to report this Wolfram Tech Support so you can get a ticket number etc. $\endgroup$ – Searke Jul 16 '18 at 20:44
  • $\begingroup$ How do I reach tech support? I was just told by support to post the problem to the community while I don't see how that would help now. $\endgroup$ – MaxJ Jul 17 '18 at 12:58
0
$\begingroup$

it seems as if ImageData is used differently on my desktop compared to the cloud. The following alteration works:

scrnet = NetInitialize@
  NetChain[{ConvolutionLayer[1, 1], PartLayer[1]}, 
   "Input" -> {1, 200, 200, 3}]
cnet = CloudExport[scrnet, "MX", "scrnet", Permissions -> "Public"]
CloudDeploy[
 FormPage[{"image" -> "Image"}, 
  With[{net = CloudImport@cnet}, Image@net@{ImageData@#image}] &], 
 Permissions -> "Public"]

Funny enough the following does not work:

With[{net = CloudImport@cnet}, Image@net@{ImageData@img}]

It seems that ImageData on my desktop converts RGB to greyscale but does not do that in the cloud.

EDIT: As people stated correctly in the comments the issue was not with ImageData[] but rather with the way the image was saved. Thanks to everyone!

Max

$\endgroup$
  • $\begingroup$ If I create Form that does (ImageData // Dimensions), I consistently see RGB output that looks like {_,_,3}. Both in Mathematica and in the cloud. I think the issue is how the NetChain handles this. $\endgroup$ – Searke Jul 17 '18 at 15:54
  • $\begingroup$ So the issue is that original image is greyscale, but if you save it or do anything to it, it'll be converted into a different colorspace. In this case, you're converting it from grayscale into an RGB colorspace so the dimensionality of the image changes. This really confused me too, but I don't think it's a bug of any kind. The correct solution for this is probably to use NetEncoder for Images to make the NetChain be more universal in the kind of input it accepts. $\endgroup$ – Searke Jul 18 '18 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.