suraj-deshmukh / keras-multi-label-image-classification Goto Github PK
View Code? Open in Web Editor NEWKeras- Multi Label Image Classification
Home Page: https://suraj-deshmukh.github.io/Keras-Multi-Label-Image-Classification/
Keras- Multi Label Image Classification
Home Page: https://suraj-deshmukh.github.io/Keras-Multi-Label-Image-Classification/
hi @suraj-deshmukh i can run you code well.
it can't call the model.predict_proba
using the function API ,not Sequence.
I check that it don't have the predict_proba
in model.
how can i sovle it? Thanks.
Hi, I am trying to do the food image classification, I have collected datasets for 199 classes. I have done classification using softmax classifier. But softmax gives sum of all probabilities equal to 1. but I need the independent class probability for each object in image
How do I can achieve this?
Hi,
the link to the dataset doesn't seem to work anymore.
Thank you
what is your tensorflow version?
this is my error message
I have successfully use my own datasets to train the model, but I got an error when I want to load my models to predict,
Using TensorFlow backend. 2018-01-03 09:47:08.570402: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX Traceback (most recent call last): File "miml.py", line 68, in <module> model.load_weights("weights.01-0.99546.hdf5") File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 733, in load_weights topology.load_weights_from_hdf5_group(f, layers) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 3143, in load_weights_from_hdf5_group K.batch_set_value(weight_value_tuples) File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 2247, in batch_set_value assign_op = x.assign(assign_placeholder) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variables.py", line 573, in assign return state_ops.assign(self._variable, value, use_locking=use_locking) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/state_ops.py", line 276, in assign validate_shape=validate_shape) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_state_ops.py", line 57, in assign use_locking=use_locking, name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2958, in create_op set_shapes_for_outputs(ret) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2209, in set_shapes_for_outputs shapes = shape_func(op) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2159, in call_with_requiring return call_cpp_shape_fn(op, require_shape_fn=True) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/common_shapes.py", line 627, in call_cpp_shape_fn require_shape_fn) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/common_shapes.py", line 691, in _call_cpp_shape_fn_impl raise ValueError(err.message) ValueError: Dimension 0 in both shapes must be equal, but are 3 and 64 for 'Assign_2' (op: 'Assign') with input shapes: [3,3,32,32], [64,32,3,3].
and this is my code
`model = Sequential()
model.add(Convolution2D(32, kernel_size=(3, 3),padding='same',input_shape=(3 , 100, 100)))
model.add(Activation('relu'))
model.add(Convolution2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Convolution2D(64,(3, 3), padding='same'))
model.add(Activation('relu'))
model.add(Convolution2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(997))
model.add(Activation('sigmoid'))
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='binary_crossentropy', optimizer=sgd, metrics=['accuracy'])
model.load_weights("weights.01-0.99546.hdf5")`
and my environment is python2, Theano (1.0.1)Keras (2.1.2)tensorflow-gpu (1.4.1)
Sorry I've seen your pull from https://github.com/anuragmishracse/caption_generator.
Test results will get poor caption.
Can you give me your training weight file on test?
Thanks
The output topK's K is fixed now.
Do you think training a classifier to predict the value of K for every input is a good solution?
Thank you very much.
https://github.com/suraj-deshmukh/Multi-Label-Image-Classification/blob/master/model.py#L47
your final output is 5 element, It should use categorical_crossentropy
i ran the code with the downloaded dataset and model weights, but the results are far from the README stated:
the hamming_loss=0.405 not 0.1395
total_correctly_predicted/400. = 0.02 not 0.54
also the label predict result of test image is:
['mountains', 'sea']
no sunset
I have some multi label datasets, can you provide me some tutorials about how to use customize datasets?
Hello there!
Thank you for your amazing code!
I have a problem to access the dataset page.
Could you give another link or share hints on how to download this dataset, please?
Thank you in advance!
accuracy will return categorical accuracy
Please either remove the blog comepletely or Update correct path in ReadMe Page
https://suraj-deshmukh.github.io/Multi-Label-Image-Classification/
I used your code to train the data with sparse labels. I found that the training effect of the model is not good. The proportion of the test data that completely correct is too small . I guess the loss function or the evaluation function is unreasonable. What good solution do you have?
i run the miml.ipynb
out = model.predict(x_test)
out = np.array(out)
got error:
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
<ipython-input-42-1e12489ae736> in <module>
----> 5 out = model.predict(x_test)
6 out = np.array(out)
/data/user1/pkgs/conda/envs/drc/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
128 raise ValueError('{} is not supported in multi-worker mode.'.format(
129 method.__name__))
--> 130 return method(self, *args, **kwargs)
131
132 return tf_decorator.make_decorator(
/data/user1/pkgs/conda/envs/drc/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in predict(self, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing)
1597 for step in data_handler.steps():
1598 callbacks.on_predict_batch_begin(step)
-> 1599 tmp_batch_outputs = predict_function(iterator)
1600 if data_handler.should_sync:
1601 context.async_wait()
/data/user1/pkgs/conda/envs/drc/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in __call__(self, *args, **kwds)
778 else:
779 compiler = "nonXla"
--> 780 result = self._call(*args, **kwds)
781
782 new_tracing_count = self._get_tracing_count()
/data/user1/pkgs/conda/envs/drc/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
812 # In this case we have not created variables on the first call. So we can
813 # run the first trace but we should fail if variables are created.
--> 814 results = self._stateful_fn(*args, **kwds)
815 if self._created_variables:
816 raise ValueError("Creating variables on a non-first call to a function"
/data/user1/pkgs/conda/envs/drc/lib/python3.7/site-packages/tensorflow/python/eager/function.py in __call__(self, *args, **kwargs)
2827 with self._lock:
2828 graph_function, args, kwargs = self._maybe_define_function(args, kwargs)
-> 2829 return graph_function._filtered_call(args, kwargs) # pylint: disable=protected-access
2830
2831 @property
/data/user1/pkgs/conda/envs/drc/lib/python3.7/site-packages/tensorflow/python/eager/function.py in _filtered_call(self, args, kwargs, cancellation_manager)
1846 resource_variable_ops.BaseResourceVariable))],
1847 captured_inputs=self.captured_inputs,
-> 1848 cancellation_manager=cancellation_manager)
1849
1850 def _call_flat(self, args, captured_inputs, cancellation_manager=None):
/data/user1/pkgs/conda/envs/drc/lib/python3.7/site-packages/tensorflow/python/eager/function.py in _call_flat(self, args, captured_inputs, cancellation_manager)
1922 # No tape is watching; skip to running the function.
1923 return self._build_call_outputs(self._inference_function.call(
-> 1924 ctx, args, cancellation_manager=cancellation_manager))
1925 forward_backward = self._select_forward_and_backward_functions(
1926 args,
/data/user1/pkgs/conda/envs/drc/lib/python3.7/site-packages/tensorflow/python/eager/function.py in call(self, ctx, args, cancellation_manager)
548 inputs=args,
549 attrs=attrs,
--> 550 ctx=ctx)
551 else:
552 outputs = execute.execute_with_cancellation(
/data/user1/pkgs/conda/envs/drc/lib/python3.7/site-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
58 ctx.ensure_initialized()
59 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 60 inputs, attrs, num_outputs)
61 except core._NotOkStatusException as e:
62 if name is not None:
InvalidArgumentError: Default MaxPoolingOp only supports NHWC on device type CPU
[[node sequential_2/max_pooling2d_3/MaxPool (defined at <ipython-input-36-3f963e6c5033>:2) ]] [Op:__inference_predict_function_862]
Function call stack:
predict_function
even i set
DATA_FORMAT = 'NHWC'
import os
os.environ['CUDA_VISIBLE_DEVICES']=""
or something like that doesnt help.
@suraj-deshmukh @bhaveshoswal
tf.version
'2.3.0'
import keras
keras.version
'2.4.3'
hey, I appreciate your nice work, it helps me a lot!
however, I use your code to train my own images which contains 137 classes. After changing your code, labels are correctly made and training seems smoothly. I get some results below and don't know if it works well. And I don't have a monitor, you know, some works are done on servers.
So what can I do to use the results below?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.