infinitered/nsfwjs

Broken with the recent file on next.js

suhjohn opened this issue · 4 comments

Previous version was working fine with next.js. Somehow I think the update on the model on Cloudfront is making this fail.

I've done the following:

  1. Download the raw zip https://github.com/GantMan/nsfw_model/releases/tag/1.1.0
  2. Copy and paste the contents of web_model_quantized in my own s3 directory.
  3. Try to use that link

Results in the following error:

Error: layer: Improper config format: {"node":[{"name":"input","op":"Placeholder","attr":{"shape":{"shape":{"dim":[{"size":"-1"},{"size":"224"},{"size":"224"},{"size":"3"}]}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/Conv/Conv2D_weights","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"3"},{"size":"3"},{"size":"3"},{"size":"48"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/expanded_conv_14/expand/Conv2D_bn_offset","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"1344"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/Conv/Conv2D_bn_offset","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"48"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/expanded_conv/depthwise/depthwise_weights","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"3"},{"size":"3"},{"size":"48"},{"size":"1"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/expanded_conv/depthwise/depthwise_bn_offset","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"48"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/expanded_conv/project/Conv2D_weights","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"1"},{"size":"1"},{"size":"48"},{"size":"24"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/expanded_conv/project/Conv2D_bn_offset","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"24"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/expanded_conv_1/expand/Conv2D_weights","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"1"},{"size":"1"},{"size":"24"},{"size":"144"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/expanded_conv_14/depthwise/depthwise_weights","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"3"},{"size":"3"},{"size":"1344"},{"size":"1"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/expanded_conv_1/expand/Conv2D_bn_offset","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"144"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/expanded_conv_1/depthwise/depthwise_weights","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"3"},{"size":"3"},{"size":"144"},{"size":"1"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/expanded_conv_1/depthwise/depthwise_bn_offset","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"144"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/expanded_conv_1/project/Conv2D_weights","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"1"},{"size":"1"},{"size":"144"},{"size":"32"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCall/StatefulPartitionedCall/predict/MobilenetV2/expanded_conv_14/depthwise/depthwise_bn_offset","op":"Const","attr":{"value":{"tensor":{"dtype":"DTFLOAT","tensorShape":{"dim":[{"size":"1344"}]}}},"dtype":{"type":"DTFLOAT"}}},{"name":"StatefulPartitionedCall/sequential/keras_layer/StatefulPartitionedCall/StatefulPartitionedCa'className' and 'config' must set.

CDN http://cloudfront.net/ is down : FetchError: request to https://d1zv2aa70wpiur.cloudfront.net/tfjs_quant_nsfw_mobilenet/model.json failed, reason: getaddrinfo ENOTFOUND d1zv2aa70wpiur.cloudfront.net

My logs :

2023-12-22T09:05:19.835173+00:00 app[web.1]: > nsfwjs-server@1.0.0 start
2023-12-22T09:05:19.835173+00:00 app[web.1]: > node server.js
2023-12-22T09:05:19.835173+00:00 app[web.1]:
2023-12-22T09:05:20.269873+00:00 app[web.1]: 2023-12-22 09:05:20.269767: I tensorflow/core/util/util.cc:169] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2023-12-22T09:05:20.305057+00:00 app[web.1]: 2023-12-22 09:05:20.304914: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 AVX512F AVX512_VNNI FMA
2023-12-22T09:05:20.305060+00:00 app[web.1]: To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-12-22T09:05:20.503512+00:00 app[web.1]:
2023-12-22T09:05:20.503513+00:00 app[web.1]: /app/node_modules/@tensorflow/tfjs-core/node_modules/node-fetch/lib/index.js:1491
2023-12-22T09:05:20.503515+00:00 app[web.1]: reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
2023-12-22T09:05:20.503515+00:00 app[web.1]: ^
2023-12-22T09:05:20.505376+00:00 app[web.1]: FetchError: request to https://d1zv2aa70wpiur.cloudfront.net/tfjs_quant_nsfw_mobilenet/model.json failed, reason: getaddrinfo ENOTFOUND d1zv2aa70wpiur.cloudfront.net
2023-12-22T09:05:20.505378+00:00 app[web.1]: at ClientRequest.<anonymous> (/app/node_modules/@tensorflow/tfjs-core/node_modules/node-fetch/lib/index.js:1491:11)
2023-12-22T09:05:20.505380+00:00 app[web.1]: at ClientRequest.emit (node:events:513:28)
2023-12-22T09:05:20.505381+00:00 app[web.1]: at TLSSocket.socketErrorListener (node:_http_client:494:9)
2023-12-22T09:05:20.505381+00:00 app[web.1]: at TLSSocket.emit (node:events:513:28)
2023-12-22T09:05:20.505381+00:00 app[web.1]: at emitErrorNT (node:internal/streams/destroy:157:8)
2023-12-22T09:05:20.505381+00:00 app[web.1]: at emitErrorCloseNT (node:internal/streams/destroy:122:3)
2023-12-22T09:05:20.505384+00:00 app[web.1]: at processTicksAndRejections (node:internal/process/task_queues:83:21) {
2023-12-22T09:05:20.505386+00:00 app[web.1]: type: 'system',
2023-12-22T09:05:20.505386+00:00 app[web.1]: errno: 'ENOTFOUND',
2023-12-22T09:05:20.505386+00:00 app[web.1]: code: 'ENOTFOUND'
2023-12-22T09:05:20.505386+00:00 app[web.1]: }
2023-12-22T09:05:20.606437+00:00 heroku[web.1]: Process exited with status 1
2023-12-22T09:05:20.628032+00:00 heroku[web.1]: State changed from starting to crashed

You can download the model here: https://github.com/infinitered/nsfwjs/tree/master/example/nsfw_demo/public/quant_mid

And point it at your own server. I'll see what's up with cloudfront and report back.

Ok, I paid the AWS bill 😄

To stop this in the future host your own copy:
https://github.com/infinitered/nsfwjs?tab=readme-ov-file#host-your-own-model