Showing posts with label classification. Show all posts
Showing posts with label classification. Show all posts

Tuesday, September 11, 2018

Tensorflow Estimator: Cache bottlenecks

Leave a Comment

When following the tensorflow image classification tutorial, at first it caches the bottleneck of each image:

def: cache_bottlenecks())

I have rewritten the training using tensorflow's Estimator. This really simplified all the code. However I want to cache the bottleneck features here.

Here is my model_fn. I want to cache the results of the dense layer so I can make changes to the actual training without having to compute the bottlenecks each time.

How can I accomplish that?

def model_fn(features, labels, mode, params):     is_training = mode == tf.estimator.ModeKeys.TRAIN      num_classes = len(params['label_vocab'])      module = hub.Module(params['module_spec'], trainable=is_training and params['train_module'])     bottleneck_tensor = module(features['image'])      with tf.name_scope('final_retrain_ops'):         logits = tf.layers.dense(bottleneck_tensor, units=num_classes, trainable=is_training)  # save this?      def train_op_fn(loss):         optimizer = tf.train.AdamOptimizer()         return optimizer.minimize(loss, global_step=tf.train.get_global_step())      head = tf.contrib.estimator.multi_class_head(n_classes=num_classes, label_vocabulary=params['label_vocab'])      return head.create_estimator_spec(         features, mode, logits, labels, train_op_fn=train_op_fn     ) 

0 Answers

Read More

Tuesday, April 3, 2018

Ways to combine two deep learning based classifiers

Leave a Comment

I want to have a primary CNN based classifier and a similar secondary classifier for image regions.

Both classifiers will be used on image regions. I need the first classifier to be used on a primary region while the secondary classifier to be used on assistive regions and will be used to support the decision made by the first classifier with further evidence.

Thus the primary image region and the assistive ones will be used to infer one class label at a time.

What other ways or architectures exist these days to perform such a task, instead of ROI Pooling?

Ideally, I would like to have a classifier scheme similar to the one of this paper but without the use of ROI Pooling.

https://arxiv.org/pdf/1505.01197.pdf

2 Answers

Answers 1

Yaw Lin's answer contains a good amount of information, I'll just build on what he said in his last paragraph. I think the essence of what you want to do is not so much to process the person and the background independently and compare the results (that's clearly what you said you're doing), but to process the background first and infer from it the kinds of expectations you have for the primary region. Once you have some expectations, you can compare the primary region to the most significant expectations.

For example, from Figure 1 (b) in your Arxiv link, if you can process the background and determine that it's outdoors in a highly populated region, then you can focus a lot of the probability density function of what the person is doing in social outdoor activities, making jogging much more likely as a guess before you even process the figure you're interested in. In contrast, for Figure 1 (a), if you can process the background and tell that it's indoors and contains computers, then you can focus probability on lone indoor computer-based activities, skyrocketing the probability of "working on a computer".

Answers 2

You can take a look at this https://arxiv.org/pdf/1611.10012.pdf which contains comprehensive survey of recent detection architectures. Basically there are 3 meta architectures and all models fall into one of those categories:

  1. Faster-RCNN: Similar to the paper you have referenced, this is the improved version of fast-rcnn which did not use selective search and directly integrate proposal generation into the network known as region proposal network(rpn).
  2. RFCN:similar in architecture to 1, except that roi pooling is performed differently, known as position sensitive roi pooling.
  3. SSD:Modifies the rpn in Faster-rcnn to directly output class probabilities, eliminating the need for per-roi computation as is done in roi pooling. This is the fastest architecture type. Yolo falls into this architecture.

I think based on my rough read through of the paper you have referenced, type 3 is the one you are looking for. However, in terms of implementation, it can be a little tricky to implement equation 3, i.e. you may need to stop backpropagating gradients to regions(or at least think about how it could effect the final results) that do not overlap with primary region as this architecture type computes probabilities for whole image.

I also note that there is in fact no primary/secondary "classifiers". The paper described primary/secondary "regions", the primary region is the region that contains the person(i.e use a person detector to find primary region first). And secondary regions are those that overlap with primary region. For activity classification there is only one classifier except that primary region carries more weight and secondary regions each contribute a little to the final prediction score.

Read More

Thursday, November 23, 2017

MATLAB: increasing sensitivity in the Classification Learner App

Leave a Comment

I have a training set of 168 instances, 12 measurements each and 2 possible categories (7 sick/ 161 healthy). I have the data arranged in a 168x13 table with the 13th row a categorical with either 'sick' or 'healthy.' I've been trying out the 2015b MATLAB Classification Learner app, using 5-10 fold cross-validation, various trees/SVMs/KNNs.

I have a 2 sets of features for 2 classes, the number of instances in the 2nd class outnumbers the number in the first class 10:1 which seems to shift the model towards a lower TPR, higher TNR. I can fix this by growing the first class with repeats of itself (class1=[class1;class1;class1]), just wondering if this is a bad solution that leads to overfitting or something similar. Is there a better strategy? Is it better to just get the best model without doing anything to the smaller class?

1 Answers

Answers 1

Your dataset is imbalanced. What you can do is either create more sick data points or interpolate the healthy data points to reduce the number of healthy data points. Trying using SMOTE and other such techniques for this. Also, decision trees would be a good start, try limiting the height of the tree.

Read More

Monday, March 28, 2016

Creating training data for a Maxent classfier in Java

Leave a Comment

I am trying to create the java implementation for maxent classifier. I need to classify the sentences into n different classes.

I had a look at ColumnDataClassifier in stanford maxent classifier. But I am not able to understand how to create training data. I need training data in the form where training data includes POS Tags for words for sentence, so that the features used for classifier will be like previous word, next word etc.

I am looking for training data which has sentences with POS TAGGING and sentence class mentioned. example :

My/(POS) name/(POS) is/(POS) XYZ/(POS) CLASS

Any help will be appreciated.

1 Answers

Answers 1

If I understand it correctly, you are trying to treat sentences as a set of POS tags.

In your example, the sentence "My name is XYZ" would be represented as a set of (PRP$, NN, VBZ, NNP). That would mean, every sentence is actually a binary vector of length 37 (because there are 36 possible POS tags according to this page + the CLASS outcome feature for the whole sentence)

This can be encoded for OpenNLP Maxent as follows:

PRP$=1 NN=1 VBZ=1 NNP=1 CLASS=SomeClassOfYours1 

or simply:

PRP$ NN VBZ NNP CLASS=SomeClassOfYours1 

(For working code-snippet see my answer here: Training models using openNLP maxent)

Some more sample data would be:

  1. "By 1978, Radio City had lost its glamour, and the owners of Rockefeller Center decided to demolish the aging hall."
  2. "In time he was entirely forgotten, many of his buildings were demolished, others insensitively altered."
  3. "As soon as she moved out, the mobile home was demolished, the suit said."
  4. ...

This would yield samples:

IN CD NNP VBD VBN PRP$ NN CC DT NNS IN TO VB VBG CLASS=SomeClassOfYours2 IN NN PRP VBD RB VBN JJ IN PRP$ NNS CLASS=SomeClassOfYours3 IN RB PRP VBD RP DT JJ NN VBN NN CLASS=SomeClassOfYours2 ... 

However, I don't expect that such a classification yields good results. It would be better to make use of other structural features of a sentence, such as the parse tree or dependency tree that can be obtained using e.g. Stanford parser.

Read More