Hi;
I tried to use "model.fit_generator" for tranning like below:
import numpy as np
import cv2
LR = 0.0001
optim = keras.optimizers.Adam(LR)
train_gen = DataGen(train_ids, train_path, image_size=image_size, batch_size=batch_size)
valid_gen = DataGen(valid_ids, train_path, image_size=image_size, batch_size=batch_size)
train_steps = len(train_ids)//batch_size
valid_steps = len(valid_ids)//batch_size
history =model.fit_generator(train_gen, validation_data=valid_gen, steps_per_epoch=train_steps, validation_steps=valid_steps,
epochs=epochs)
But I got the below error, any clue why:
Epoch 1/10
InvalidArgumentError Traceback (most recent call last)
C:\Users\awr431.LPI\AppData\Local\Temp/ipykernel_21236/2228345826.py in
12 valid_steps = len(valid_ids)//batch_size
13
---> 14 history =model.fit_generator(train_gen, validation_data=valid_gen, steps_per_epoch=train_steps, validation_steps=valid_steps,
15 epochs=epochs)
D:\anaconda3\lib\site-packages\keras\engine\training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
2207 'Please use Model.fit
, which supports generators.',
2208 stacklevel=2)
-> 2209 return self.fit(
2210 generator,
2211 steps_per_epoch=steps_per_epoch,
D:\anaconda3\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
D:\anaconda3\lib\site-packages\tensorflow\python\eager\execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
52 try:
53 ctx.ensure_initialized()
---> 54 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
55 inputs, attrs, num_outputs)
56 except core._NotOkStatusException as e:
InvalidArgumentError: Graph execution error:
Detected at node 'model_1/patch_extract/Reshape' defined at (most recent call last):
File "D:\anaconda3\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "D:\anaconda3\lib\site-packages\ipykernel_launcher.py", line 16, in
app.launch_new_instance()
File "D:\anaconda3\lib\site-packages\traitlets\config\application.py", line 846, in launch_instance
app.start()
File "D:\anaconda3\lib\site-packages\ipykernel\kernelapp.py", line 677, in start
self.io_loop.start()
File "D:\anaconda3\lib\site-packages\tornado\platform\asyncio.py", line 199, in start
self.asyncio_loop.run_forever()
File "D:\anaconda3\lib\asyncio\base_events.py", line 596, in run_forever
self._run_once()
File "D:\anaconda3\lib\asyncio\base_events.py", line 1890, in _run_once
handle._run()
File "D:\anaconda3\lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "D:\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 457, in dispatch_queue
await self.process_one()
File "D:\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 446, in process_one
await dispatch(*args)
File "D:\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 353, in dispatch_shell
await result
File "D:\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 648, in execute_request
reply_content = await reply_content
File "D:\anaconda3\lib\site-packages\ipykernel\ipkernel.py", line 353, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "D:\anaconda3\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "D:\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2901, in run_cell
result = self._run_cell(
File "D:\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2947, in _run_cell
return runner(coro)
File "D:\anaconda3\lib\site-packages\IPython\core\async_helpers.py", line 68, in pseudo_sync_runner
coro.send(None)
File "D:\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3172, in run_cell_async
has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
File "D:\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3364, in run_ast_nodes
if (await self.run_code(code, result, async=asy)):
File "D:\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3444, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "C:\Users\60962~1.LPI\AppData\Local\Temp/ipykernel_21236/2228345826.py", line 14, in
history =model.fit_generator(train_gen, validation_data=valid_gen, steps_per_epoch=train_steps, validation_steps=valid_steps,
File "D:\anaconda3\lib\site-packages\keras\engine\training.py", line 2209, in fit_generator
return self.fit(
File "D:\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 64, in error_handler
return fn(*args, **kwargs)
File "D:\anaconda3\lib\site-packages\keras\engine\training.py", line 1384, in fit
tmp_logs = self.train_function(iterator)
File "D:\anaconda3\lib\site-packages\keras\engine\training.py", line 1021, in train_function
return step_function(self, iterator)
File "D:\anaconda3\lib\site-packages\keras\engine\training.py", line 1010, in step_function
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "D:\anaconda3\lib\site-packages\keras\engine\training.py", line 1000, in run_step
outputs = model.train_step(data)
File "D:\anaconda3\lib\site-packages\keras\engine\training.py", line 859, in train_step
y_pred = self(x, training=True)
File "D:\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 64, in error_handler
return fn(*args, **kwargs)
File "D:\anaconda3\lib\site-packages\keras\engine\base_layer.py", line 1096, in call
outputs = call_fn(inputs, *args, **kwargs)
File "D:\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 92, in error_handler
return fn(*args, **kwargs)
File "D:\anaconda3\lib\site-packages\keras\engine\functional.py", line 451, in call
return self._run_internal_graph(
File "D:\anaconda3\lib\site-packages\keras\engine\functional.py", line 589, in _run_internal_graph
outputs = node.layer(*args, **kwargs)
File "D:\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 64, in error_handler
return fn(*args, **kwargs)
File "D:\anaconda3\lib\site-packages\keras\engine\base_layer.py", line 1096, in call
outputs = call_fn(inputs, *args, **kwargs)
File "D:\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 92, in error_handler
return fn(args, **kwargs)
File "C:\Users\awr43~1.LPI\AppData\Local\Temp/ipykernel_21236/3106607235.py", line 50, in call
patches = tf.reshape(patches, (batch_size, patch_numpatch_num, patch_dim))
Node: 'model_1/patch_extract/Reshape'
Input to reshape is a tensor with 196608 values, but the requested shape has 49152
[[{{node model_1/patch_extract/Reshape}}]] [Op:__inference_train_function_27828]