Jupyter Notebook Sync

Hi Edge Impulse Team,

I have seen the Jupyter Notebook option and I can download and open it locally in my pc and it connects to EI. However, I already had to install some libs locally (requests, tensorflow, sklearn), but the autogenerated training code does not seem to work (project 77221). So based on that I have a few questions:

  • i) How do I get the notebook running?
  • ii) How do I sync back the results. E. g. if I change the model code and save then I see no change in the model code in Python view (of the EI studio)

Regards

Lukas

Hallo Lukas,

What are the errors?

This is a good question.
I am also am exploring this. You need to use EI API (https://docs.edgeimpulse.com/reference/setkeras) You need to write some coding that “translates” the model structure into the payload.

Regards,
J.

Hi,

this is my error:


InvalidArgumentError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_14656\671196431.py in
26 # train the neural network
27 model.compile(loss=‘mean_squared_error’, optimizer=opt)
—> 28 model.fit(train_dataset, epochs=1, validation_data=validation_dataset, verbose=2, callbacks=callbacks)

c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\keras\utils\traceback_utils.py in error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.traceback)
—> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb

c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\tensorflow\python\eager\execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
57 ctx.ensure_initialized()
58 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
—> 59 inputs, attrs, num_outputs)
60 except core._NotOkStatusException as e:
61 if name is not None:

InvalidArgumentError: Incompatible shapes: [32,2,908] vs. [32,908]
[[node gradient_tape/mean_squared_error/BroadcastGradientArgs
(defined at c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\keras\optimizer_v2\optimizer_v2.py:464)
]] [Op:__inference_train_function_1292]

Errors may have originated from an input operation.
Input Source operations connected to node gradient_tape/mean_squared_error/BroadcastGradientArgs:
In[0] gradient_tape/mean_squared_error/Shape_4:
In[1] gradient_tape/mean_squared_error/Shape_5:

Operation defined at: (most recent call last)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\runpy.py”, line 193, in _run_module_as_main
main”, mod_spec)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\runpy.py”, line 85, in _run_code
exec(code, run_globals)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\ipykernel_launcher.py”, line 16, in
app.launch_new_instance()

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\traitlets\config\application.py”, line 846, in launch_instance
app.start()

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\ipykernel\kernelapp.py”, line 677, in start
self.io_loop.start()

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\tornado\platform\asyncio.py”, line 199, in start
self.asyncio_loop.run_forever()

File “c:\users\lukas\appdata\local\programs\python\python37\lib\asyncio\base_events.py”, line 541, in run_forever
self._run_once()

File “c:\users\lukas\appdata\local\programs\python\python37\lib\asyncio\base_events.py”, line 1786, in _run_once
handle._run()

File “c:\users\lukas\appdata\local\programs\python\python37\lib\asyncio\events.py”, line 88, in _run
self._context.run(self._callback, *self._args)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\ipykernel\kernelbase.py”, line 461, in dispatch_queue
await self.process_one()

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\ipykernel\kernelbase.py”, line 450, in process_one
await dispatch(*args)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\ipykernel\kernelbase.py”, line 357, in dispatch_shell
await result

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\ipykernel\kernelbase.py”, line 652, in execute_request
reply_content = await reply_content

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\ipykernel\ipkernel.py”, line 353, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\ipykernel\zmqshell.py”, line 532, in run_cell
return super().run_cell(*args, **kwargs)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\IPython\core\interactiveshell.py”, line 2915, in run_cell
raw_cell, store_history, silent, shell_futures)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\IPython\core\interactiveshell.py”, line 2960, in _run_cell
return runner(coro)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\IPython\core\async_helpers.py”, line 78, in _pseudo_sync_runner
coro.send(None)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\IPython\core\interactiveshell.py”, line 3186, in run_cell_async
interactivity=interactivity, compiler=compiler, result=result)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\IPython\core\interactiveshell.py”, line 3377, in run_ast_nodes
if (await self.run_code(code, result, async_=asy)):

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\IPython\core\interactiveshell.py”, line 3457, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)

File “C:\Users\lukas\AppData\Local\Temp\ipykernel_14656\671196431.py”, line 28, in
model.fit(train_dataset, epochs=1, validation_data=validation_dataset, verbose=2, callbacks=callbacks)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\keras\utils\traceback_utils.py”, line 64, in error_handler
return fn(*args, **kwargs)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\keras\engine\training.py”, line 1216, in fit
tmp_logs = self.train_function(iterator)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\keras\engine\training.py”, line 878, in train_function
return step_function(self, iterator)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\keras\engine\training.py”, line 867, in step_function
outputs = model.distribute_strategy.run(run_step, args=(data,))

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\keras\engine\training.py”, line 860, in run_step
outputs = model.train_step(data)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\keras\engine\training.py”, line 816, in train_step
self.optimizer.minimize(loss, self.trainable_variables, tape=tape)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\keras\optimizer_v2\optimizer_v2.py”, line 531, in minimize
loss, var_list=var_list, grad_loss=grad_loss, tape=tape)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\keras\optimizer_v2\optimizer_v2.py”, line 583, in _compute_gradients
grads_and_vars = self._get_gradients(tape, loss, var_list, grad_loss)

File “c:\users\lukas\appdata\local\programs\python\python37\lib\site-packages\keras\optimizer_v2\optimizer_v2.py”, line 464, in _get_gradients
grads = tape.gradient(loss, var_list, grad_loss)

Do you have a minimal example for this API usage?

@Lukas

I assume your model runs successfully on the EI platform?

Maybe, try to setup a new conda env. Below the content of the environment yml-file with the needed dependencies.

name: tf_venv
channels: 
  - conda-forge
  - defaults
dependencies:
  - python=3.8
  - scikit-learn=1.0.2
  - tensorflow=2.6.2
  - jupyterlab=3.2.6
  - requests=2.27.1

I also explore what is possible, so it is still a work in progress. I will share with the community as soon I have some results.

But on https://docs.edgeimpulse.com/reference/setkeras you can request an example:

This you can use as a starting point.

1 Like