Disclaimer: I know very little Javascript
I'm trying to run a TensorflowJS in a Django instance, I can successfully load the JS to call the tf.loadLayersModel
function, however this function requires a json file (and another .bin file later) to run and the function isnt able to find it.
Both the files (json and bin) are in the expected static directory (the same that loaded the JS file in the first place), but everytime I load the page Django returns Not Found: /myapp/test_model/model.json
and the browser returns (through Inspect Element) Error: Request to model.json failed with status code 404. Please verify this URL points to the model JSON of the model to load.
I'm using in settings.py:
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
Directory:
myproject/
++ static/ #(created by django)
++ __init__.py
++ settings.py
++ ...
myapp/
static/ #(where I'm putting the files)
++ myapp/
++++ test_model/
++++++ model.json
++++++ otherfile.bin
manage.py
So the files are put in the static/myapp/test_model/
and after that i run python manage.py collectstatic
the files get reconized, and copy to myproject/static/myapp/test_model/
The .html loaded at the view: (localhost/myapp/test_model/)
<html>
<head>
{% load static %}
...
<script src = "{% static "myapp/test_model/main.js" %}" > </script>
</head>
<body>
...
</body>
{% block javascript %}
<script>
start()
</script>
{% endblock %}
</html>
Javascript:
async function start() {
model = await tf.loadLayersModel('model.json')
model.predict(tf.zeros([1, 28, 28, 1]))
await loadClasses()
}
However when I load the page the model doesn't load AND django console returns:
Not Found: /myapp/test_model/model.json