Giter Site home page Giter Site logo

weakly_detector's Introduction

Weakly_detector

Tensorflow implementation of "Learning Deep Features for Discriminative Localization"

B. Zhou, A. Khosla, A. Lapedriza, A. Oliva, and A. Torralba Learning Deep Features for Discriminative Localization. Computer Vision and Pattern Recognition (CVPR), 2016. [PDF][Project Page]

Results of Caltech256 Dataset

alt tag

Results of Action40 Dataset

alt tag Object localization using only image-level annotation, without bounding box annotation.

  • If you want to train the model using custom dataset, you need the pretrained VGG Network weights [VGG], which is used in [code].

weakly_detector's People

Contributors

jazzsaxmafia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

weakly_detector's Issues

TypeError: 'map' object is not subscriptable

@jazzsaxmafia Hello,
:\Tesnsorflow\Weaklydetector\src>python train.caltech.py
Traceback (most recent call last):
File "train.caltech.py", line 44, in
image_paths_train = np.hstack(map(lambda one_class: one_class[:-10], image_paths_per_label))
File "C:\Program Files\Anaconda3\lib\site-packages\numpy\core\shape_base.py", line 275, in hstack
arrs = [atleast_1d(_m) for _m in tup]
File "C:\Program Files\Anaconda3\lib\site-packages\numpy\core\shape_base.py", line 275, in
arrs = [atleast_1d(_m) for _m in tup]
File "train.caltech.py", line 44, in
image_paths_train = np.hstack(map(lambda one_class: one_class[:-10], image_paths_per_label))
TypeError: 'map' object is not subscriptable


:\Tesnsorflow\Weaklydetector\src>python train.caltech.py
Traceback (most recent call last):
File "train.caltech.py", line 40, in
image_paths_train = np.hstack(list(map(lambda one_class: one_class[:-10], image_paths_per_label)))
File "train.caltech.py", line 40, in
image_paths_train = np.hstack(list(map(lambda one_class: one_class[:-10], image_paths_per_label)))
TypeError: 'map' object is not subscriptable

Any idea of this problem? Thank you very much.

Fine tuning

How to fine tune your model? I don't have sufficient data to retrain your model from scratch.I want to fine tune your model on my data which has only two classes ?

Solved: ValueError: invalid literal for int() with base 10: ''

What I did so far:

  1. I downloaded the caltech256 dataset from kaggle (link: https://www.kaggle.com/jessicali9530/caltech256)
  2. put the zip into the folder (~/WeaklyDetector/data/)
  3. extracted the zip and
  4. adjusted the variable 'dataset_path' in train.caltech.py (line 19) to (~/WeaklyDetector/data/256_ObjectCategories)

As i run the train.caltech.py file, following error occured:
ValueError: invalid literal for int() with base 10: ''

What the algorithm does:

The algorithm reads all foldernames in the path we previously set in step 4 and split the name by the delimiter '.'. The numbers are stored in the variable 'labels' and the name of the corresponding classes in 'label_names' (line 32). So the algorithm expects this folder only to contain folders with the scheme '[0-9]+.[A-z_-]+'. (in other words, there are some numbers, followed by a point and a name).

What raised the error and how to solve:

In the folder of step 4 there is a hidden folder, called '.DS_Store'. Apparently- this folder does not match the desired scheme. It seems to be necessary for mac users, though. With help of print commands i verified that the algorithm reads this folder. Splitting the name as described in the previous section leads to the empty label '' and the label_name 'DS_Store'. The algorithm tries to map the empty label to an int value, that is of course impossible.

Just remove that file and it should work. Or try to filter this specific file in the program.

Wrong activation maps.

I am using your technique to obtain activation maps for only one class in a binary classification problem. The network I have trained is inception v3. I cut the last 3 inception modules and then I added a new convolutional layer, a gap layer and a softmax. The input of the new convolutional layer has shape batch_size x 17 x 17 x 768 and the output's shape is batch_size x 17 x 17 x 1024, using 3 x 3 kernel. The precision of the network is high (89%). Do you have idea what might be wrong? I have not changed your technique.

Training Loss: nan

I tried training a model on this but I keep getting 'Training Loss: nan'
I trained for 17 epochs before I stopped because of this.
Is it that the model is not learning or could it be a different issue?

Cannot obtain right activation map.

I have trained inception v3 network and I have achieved high precision. I am cutting the last 3 inception modules of the network and the output of the last module is batch_size x 17 x 17 x 768. In the next steps I am using your technique to get activation map of each image but results are bad. The output classes are only 2 and I want to have right activation maps only for the one class. Can you tell me what am I missing? Here is the code:

`
def conv2d(input_image, name):
filter_shape = [3, 3, 768, 1024]
with tf.name_scope('MyConv'):
w = tf.Variable(tf.random_uniform(filter_shape, minval=0.0, maxval=0.01), name='weights')
b = tf.Variable(tf.zeros(filter_shape[-1]), name='biases')

	conv = tf.nn.conv2d(input_image, w, [1,1,1,1], padding='SAME')
	outputs = tf.nn.bias_add(conv, b)

return outputs

`

`def add_final_training_ops(net, ground_truth_input, class_count, final_tensor_name):

# Convolutional layer
convoluted = conv2d(net, 'NewConvLayer')

# GAP layer
gap = tf.reduce_mean(convoluted, [1, 2])

# Organizing the following ops as `final_training_ops` so they're easier
# to see in TensorBoard
layer_name = 'final_training_ops'
with tf.name_scope(layer_name):
	with tf.name_scope('weights'):
		layer_weights = tf.Variable(tf.random_uniform([1024, class_count], minval=0.0, maxval=0.01),
													name='final_weights')

	with tf.name_scope('Wx_plus_b'):
		logits = tf.matmul(gap, layer_weights)

final_tensor = tf.nn.softmax(logits, name=final_tensor_name)

return final_tensor, layer_weights, convoluted`

`def heat_map(image, softmax_weights, labels):
img_resize = tf.image.resize_bilinear(image, [299, 299])
with tf.variable_scope("GAP", reuse=True):
label_w = tf.gather(tf.transpose(softmax_weights), labels)
label_w = tf.reshape(label_w, [-1, 1024, 1]) # [batch_size, 1024, 1]

img_resize = tf.reshape(img_resize, [-1, 299299, 1024]) # [batch_size, 299299, 1024]
activation = tf.batch_matmul(img_resize, label_w)
activation = tf.reshape(activation, [-1, 299, 299])
return activation`

`final_tensor, softmax_weights, convoluted = add_final_training_ops(inception_7, labels,
num_classes, 'final_result')

	prediction = tf.argmax(final_tensor, 1)
	activation_map = heat_map(convoluted, softmax_weights, labels)`

something about action40

hi, can you tell me how you train action40 datasets? Does you retrain the whole network?
I don't get the same good results as yours.

thanks

What's the model_path???

What's the model_path??? The code : model_path = '/home/xxx/' is enough ??? Maybe is it a type of .tfmodel or .caffemodel??? For exampel, the code maight : mdoel_path=''/home/xxx/vgg16.tfmodel'???

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.