SadmanSakib93 / Stratified-k-fold-cross-validation-Image-classification-keras

This python program demonstrates image classification with stratified k-fold cross validation technique.
33 stars 15 forks source link

Classes mismatch problem #3

Open Nageshwar06 opened 2 years ago

Nageshwar06 commented 2 years ago

Dear Sir, i was testing the code with same dataset that you have posted in github for Image classification via k-fold-cross validation but I have gotten the issue related with classes that it should be 3 but during the running of code I have gotten 4 classes. So shape mismatch problem is showing i.e. [190 3] vs [190 4]. So please resolve this issue as soon as possible. For better understanding Output that was coming, attached below.......

Results for fold 1 Found 191 images belonging to 4 classes. Found 64 images belonging to 4 classes. /usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:46: UserWarning: Model.fit_generator is deprecated and will be removed in a future version. Please use Model.fit, which supports generators. Epoch 1/100

InvalidArgumentError Traceback (most recent call last)

in () 44 # fit model 45 history=model.fit_generator(train_generator, ---> 46 epochs=EPOCHS) 47 48 predictions = model.predict_generator(validation_generator, verbose=1)
SadmanSakib93 commented 2 years ago

Dear Sir, i was testing the code with same dataset that you have posted in github for Image classification via k-fold-cross validation but I have gotten the issue related with classes that it should be 3 but during the running of code I have gotten 4 classes. So shape mismatch problem is showing i.e. [190 3] vs [190 4]. So please resolve this issue as soon as possible. For better understanding Output that was coming, attached below.......

Results for fold 1

Found 191 images belonging to 4 classes. Found 64 images belonging to 4 classes. /usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:46: UserWarning: Model.fit_generator is deprecated and will be removed in a future version. Please use Model.fit, which supports generators. Epoch 1/100

InvalidArgumentError Traceback (most recent call last) in () 44 # fit model 45 history=model.fit_generator(train_generator, ---> 46 epochs=EPOCHS) 47 48 predictions = model.predict_generator(validation_generator, verbose=1)

Hi, could you please share more details of the error? I checked the script on my end again, it still works fine.

Nageshwar06 commented 2 years ago

Results for fold 1 Found 191 images belonging to 4 classes. Found 64 images belonging to 4 classes.

/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:46: UserWarning: Model.fit_generator is deprecated and will be removed in a future version. Please use Model.fit, which supports generators.

Epoch 1/100


InvalidArgumentError Traceback (most recent call last)

in () 44 # fit model 45 history=model.fit_generator(train_generator, ---> 46 epochs=EPOCHS) 47 48 predictions = model.predict_generator(validation_generator, verbose=1) 2 frames /usr/local/lib/python3.7/dist-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: required broadcastable shapes [[node binary_crossentropy/logistic_loss/mul (defined at /usr/local/lib/python3.7/dist-packages/keras/backend.py:5158) ]] [Op:__inference_train_function_1634] Errors may have originated from an input operation. Input Source operations connected to node binary_crossentropy/logistic_loss/mul: In[0] sequential/dense_3/BiasAdd (defined at /usr/local/lib/python3.7/dist-packages/keras/layers/core/dense.py:210) In[1] IteratorGetNext (defined at /usr/local/lib/python3.7/dist-packages/keras/engine/training.py:866) Operation defined at: (most recent call last) >>> File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main >>> "__main__", mod_spec) >>> >>> File "/usr/lib/python3.7/runpy.py", line 85, in _run_code >>> exec(code, run_globals) >>> >>> File "/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py", line 16, in >>> app.launch_new_instance() >>> >>> File "/usr/local/lib/python3.7/dist-packages/traitlets/config/application.py", line 846, in launch_instance >>> app.start() >>> >>> File "/usr/local/lib/python3.7/dist-packages/ipykernel/kernelapp.py", line 499, in start >>> self.io_loop.start() >>> >>> File "/usr/local/lib/python3.7/dist-packages/tornado/platform/asyncio.py", line 132, in start >>> self.asyncio_loop.run_forever() >>> >>> File "/usr/lib/python3.7/asyncio/base_events.py", line 541, in run_forever >>> self._run_once() >>> >>> File "/usr/lib/python3.7/asyncio/base_events.py", line 1786, in _run_once >>> handle._run() >>> >>> File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run >>> self._context.run(self._callback, *self._args) >>> >>> File "/usr/local/lib/python3.7/dist-packages/tornado/platform/asyncio.py", line 122, in _handle_events >>> handler_func(fileobj, events) >>> >>> File "/usr/local/lib/python3.7/dist-packages/tornado/stack_context.py", line 300, in null_wrapper >>> return fn(*args, **kwargs) >>> >>> File "/usr/local/lib/python3.7/dist-packages/zmq/eventloop/zmqstream.py", line 452, in _handle_events >>> self._handle_recv() >>> >>> File "/usr/local/lib/python3.7/dist-packages/zmq/eventloop/zmqstream.py", line 481, in _handle_recv >>> self._run_callback(callback, msg) >>> >>> File "/usr/local/lib/python3.7/dist-packages/zmq/eventloop/zmqstream.py", line 431, in _run_callback >>> callback(*args, **kwargs) >>> >>> File "/usr/local/lib/python3.7/dist-packages/tornado/stack_context.py", line 300, in null_wrapper >>> return fn(*args, **kwargs) >>> >>> File "/usr/local/lib/python3.7/dist-packages/ipykernel/kernelbase.py", line 283, in dispatcher >>> return self.dispatch_shell(stream, msg) >>> >>> File "/usr/local/lib/python3.7/dist-packages/ipykernel/kernelbase.py", line 233, in dispatch_shell >>> handler(stream, idents, msg) >>> >>> File "/usr/local/lib/python3.7/dist-packages/ipykernel/kernelbase.py", line 399, in execute_request >>> user_expressions, allow_stdin) >>> >>> File "/usr/local/lib/python3.7/dist-packages/ipykernel/ipkernel.py", line 208, in do_execute >>> res = shell.run_cell(code, store_history=store_history, silent=silent) >>> >>> File "/usr/local/lib/python3.7/dist-packages/ipykernel/zmqshell.py", line 537, in run_cell >>> return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs) >>> >>> File "/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py", line 2718, in run_cell >>> interactivity=interactivity, compiler=compiler, result=result) >>> >>> File "/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py", line 2822, in run_ast_nodes >>> if self.run_code(code, result): >>> >>> File "/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py", line 2882, in run_code >>> exec(code_obj, self.user_global_ns, self.user_ns) >>> >>> File "", line 46, in >>> epochs=EPOCHS) >>> >>> File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 2030, in fit_generator >>> initial_epoch=initial_epoch) >>> >>> File "/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py", line 64, in error_handler >>> return fn(*args, **kwargs) >>> >>> File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1216, in fit >>> tmp_logs = self.train_function(iterator) >>> >>> File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 878, in train_function >>> return step_function(self, iterator) >>> >>> File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 867, in step_function >>> outputs = model.distribute_strategy.run(run_step, args=(data,)) >>> >>> File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 860, in run_step >>> outputs = model.train_step(data) >>> >>> File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 810, in train_step >>> y, y_pred, sample_weight, regularization_losses=self.losses) >>> >>> File "/usr/local/lib/python3.7/dist-packages/keras/engine/compile_utils.py", line 201, in __call__ >>> loss_value = loss_obj(y_t, y_p, sample_weight=sw) >>> >>> File "/usr/local/lib/python3.7/dist-packages/keras/losses.py", line 141, in __call__ >>> losses = call_fn(y_true, y_pred) >>> >>> File "/usr/local/lib/python3.7/dist-packages/keras/losses.py", line 245, in call >>> return ag_fn(y_true, y_pred, **self._fn_kwargs) >>> >>> File "/usr/local/lib/python3.7/dist-packages/keras/losses.py", line 1807, in binary_crossentropy >>> backend.binary_crossentropy(y_true, y_pred, from_logits=from_logits), >>> >>> File "/usr/local/lib/python3.7/dist-packages/keras/backend.py", line 5158, in binary_crossentropy >>> return tf.nn.sigmoid_cross_entropy_with_logits(labels=target, logits=output) >>> **Dear Sir, I am sharing the complete shot of error as per information. Yesterday, I tried to see the folder of dataset **DS** and found that it was showing four folder under training set Among four, three was ['circles', 'squares', 'triangles'] and one automatically created file that was **.ipynb_checkpoints**. I have deleted the same using **rmdir** command but still the same error was coming as mentioned above. Please look into the issue.**
SadmanSakib93 commented 2 years ago

Is the program (.ipynb code) kept inside the DS folder? Please try to run the notebook in the same structure as given here in the repo.