Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick Questions #9

Closed
akshaylamba opened this issue Sep 15, 2017 · 32 comments
Closed

Quick Questions #9

akshaylamba opened this issue Sep 15, 2017 · 32 comments

Comments

@akshaylamba
Copy link

akshaylamba commented Sep 15, 2017

Hello

Are you using Multiscale Training of Data..also You have Pretrained Weights on VOC Data ...Below is the Image of Blood Smear :-
111

I Want to Detect The Purple Color and Red Color Cells...I have Done the Annotations ...
I Only have 300 Images With Me with 15-20 Annotation in an Image...What do u Recommand ...

@akshaylamba akshaylamba changed the title which Yolo is This.. Quick Questions Sep 15, 2017
@experiencor
Copy link
Owner

I'm NOT using Multiscale Training.

Yes, I have the pre-trained weights on VOC data. It's here #6.

I think that 300 images are good enough if you use the pre-trained weights and extensive data augmentation.

@akshaylamba
Copy link
Author

@experiencor ...Thanks For your Suggestion ...

Is there a Difference in Weights Downloaded as tiny-yolo-voc.weights and the link you provided...

and also apart from the Data augmentation you wrote in your code ..What Other data augmentation do u suggest...

@experiencor
Copy link
Owner

experiencor commented Sep 16, 2017

They are identical. For best result, you may look at object detection code by Google for more advanced data augmentation https://github.com/tensorflow/models/blob/master/object_detection/core/preprocessor.py.

@cosmicad
Copy link

cosmicad commented Sep 21, 2017

Thanks for your reply...
Also does the Code have an implementation for Anchor Boxes like Faster RCNN ..I Suppose YOLO V2 has tried implementing anchor boxes like Faster RCNN .... Have we Implemented KMean to select the box.

Pls Let me know your Views ...

@experiencor
Copy link
Owner

Yes, the anchor boxes are implemented in YOLOv2 and my version too. A set of 5 anchor boxes is used.

@cosmicad
Copy link

Thanks For your Reply...
Below is the Detection Result of the Model
20_p_thre_221

The Threshold is set to 0.20 ..How Can I Increase the Threshold to 0.4-0.5 and get the same Result...As I Increase the Threshold The Number of Detections Decreases ...I Think Increasing the data May Help ....Pls Suggest Other ways We can achieve this ...

@experiencor
Copy link
Owner

experiencor commented Sep 23, 2017

@cosmicad great job! Why do you want to increase the threshold in the first place? The result seems good enough already. Increasing the data always helps, but it takes time. Shorter way is to artificially augment existing images (try to rotate the images, change brightness, add random dropouts, ... like in this https://github.com/aleju/imgaug). In addition, I'm in the process of coding up a new loss function, which may improve the result. Stay tuned.

@experiencor
Copy link
Owner

experiencor commented Sep 25, 2017

I see that your case is highly unbalanced. The best way I know of to deal with this issue to penalize the classification loss differently for different classes. You can try to change the following 2 lines that define the weights of the classification errors for that purpose:

weight_prob = tf.concat(CLASS * [true_box_conf], 4) 
weight_prob = SCALE_PROB * weight_prob 

I'm very curious with the result. Please update me if possible.

@akshaylamba
Copy link
Author

Definitely sir... I would request you to elaborate on the same...with a small example ...I would definitely catch up and come up with a result...

@experiencor
Copy link
Owner

experiencor commented Sep 26, 2017

You may want to check the new code. The weights of the classes are specified in CLASS_WEIGHTS = np.ones(CLASS, dtype='float32'), which is an array of floats (must be float32). The size of the array is exactly the number of the classes. I achieve class re-weighting by the call to tf.gather in line:

class_mask = y_true[..., 4] * tf.gather(CLASS_WEIGHTS, true_box_class) * CLASS_SCALE

Please note that I have made substantial changes to the loss function to closely follow the original implementation. The architecture has also been changed from the tiny version (9 layers) to the full version (23 layers). The new architecture is much more accurate but will be a bit lower than the old one.

@akshaylamba
Copy link
Author

changing the no of labels from 80 to 1 or 2 or 3 Gives the below error :


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-21-b9944f13ff2f> in <module>()
    125 # Layer 23
    126 x = Conv2D(425, (1,1), strides=(1,1), padding='same', name='conv_23')(x)
--> 127 output = Reshape((GRID_H, GRID_W, BOX, 4 + 1 + CLASS))(x)
    128 
    129 # small hack to allow true_boxes to be registered when Keras build the model

/usr/local/lib/python2.7/dist-packages/keras/engine/topology.pyc in __call__(self, inputs, **kwargs)
    619             # Infering the output shape is only relevant for Theano.
    620             if all([s is not None for s in _to_list(input_shape)]):
--> 621                 output_shape = self.compute_output_shape(input_shape)
    622             else:
    623                 if isinstance(input_shape, list):

/usr/local/lib/python2.7/dist-packages/keras/layers/core.pyc in compute_output_shape(self, input_shape)
    374     def compute_output_shape(self, input_shape):
    375         return (input_shape[0],) + self._fix_unknown_dimension(
--> 376             input_shape[1:], self.target_shape)
    377 
    378     def call(self, inputs):

/usr/local/lib/python2.7/dist-packages/keras/layers/core.pyc in _fix_unknown_dimension(self, input_shape, output_shape)
    368             output_shape[unknown] = original // known
    369         elif original != known:
--> 370             raise ValueError(msg)
    371 
    372         return tuple(output_shape)

ValueError: total size of new array must be unchanged

@experiencor
Copy link
Owner

It's fixed. The reason is that I need to vary the number of filters of the last layer according to the number of labels.

@cosmicad
Copy link

I tried your new code...I tried training only one class for detection ... Do not Why the Detection was not Good...May be I am Doing something Wrong with the code...

Below is the Link of Jupyter notebook for your reference :-
https://github.com/cosmicad/newyolo_RBC/blob/master/Basic%20Yolo%20Keras.ipynb

Pls review it...It contains all executions with outputs...

I am Thanksful to you for your Efforts and Time you spend in resolving my query ...

Pls let me know your views..

@experiencor
Copy link
Owner

The issue is that the non-predictor anchors tend to be activated at the same time with the predictor anchor. I have the same issue with training with any one class problem. So I think you are doing it right. However, I don't have this issue with training with many classes like in the COCO dataset (80 classes). Seems to be a complex issue, still debugging ...

@experiencor
Copy link
Owner

experiencor commented Oct 1, 2017

I got the one class case to work. Just to tweak the parameters. The tweaks that I used to get it working are:

  1. Use large batch size (I used 16).
  2. Change WARM_UP_BATCHES to 100 (this parameter defines the number of initial batches during which the network gets familiar with the new dataset).
  3. Turn on jitter in the training generator:

From this:

train_batch = BatchGenerator(train_img, generator_config, jitter=False)

To this:

train_batch = BatchGenerator(train_img, generator_config)
  1. Train on a few training epoches before validating:

From:

steps_per_epoch  = train_batch.get_dateset_size()

To:

steps_per_epoch  = train_batch.get_dateset_size() * 5

The last 2 steps are essential to deal with the small size of your dataset.

This is the result: a Raccoon Detector (https://www.youtube.com/watch?v=aibuvj2-zxA) trained on 160 images using the dataset from https://github.com/datitran/raccoon_dataset. This the reference video by the author of the dataset using Google API if you want to know how well the network does (https://www.youtube.com/watch?v=W0sRoho8COI).

So you may try a combination of these tweaks to see if it work. Let me know the results if possible.

@akshaylamba
Copy link
Author

akshaylamba commented Oct 2, 2017

tried Using your technique but No Luck .....I do not know what incorrect am I doing ...

I request u to help me out with my dataset once...Pls ...

dataset Link >>> https://github.com/cosmicad/dataset.git
Class Label = " RBC "

I am Thanksful to you for your Efforts and Time you spend in resolving my query ...

Regards
Akshay

@experiencor
Copy link
Owner

Ok, sure. I take a look.

@experiencor
Copy link
Owner

experiencor commented Oct 3, 2017

This is what I get https://github.com/experiencor/basic-yolo-keras/blob/master/examples/Blood%20Cell%20Detection.ipynb.

This result is okay, right?

BTW, is it fine if I put the result of your application to the readme of this repo?

@akshaylamba
Copy link
Author

Yes ... I tried Doing Multiclass Detection With the same data set...Below is the results :
233_te
408

If you could Kindly Guide me on Calculating the MAP , Recall / Precision ....

@experiencor
Copy link
Owner

experiencor commented Oct 11, 2017

@akshaylamba Congratulate! The result looks stunning to me.

You can use this script to compute mean precision and recall https://github.com/rbgirshick/py-faster-rcnn/blob/master/lib/datasets/voc_eval.py. It's a very dirty script. Otherwise, you can use this one https://github.com/cocodataset/cocoapi. You have to convert from the annotations from VOC to COCO to use the latter one.

@akshaylamba
Copy link
Author

Hello @experiencor ... I Could Not respond as was Bad on Health...
I tried Using your Code for Calculating the MAP , Recall / Precision but could not succeed ..

Can You guide me...

@experiencor
Copy link
Owner

@akshaylamba I'm still finding time to clean my own evaluation code. Will update the code asap.

@experiencor
Copy link
Owner

@akshaylamba You may try the code suggested in #27.

@akshaylamba
Copy link
Author

@experiencor ... I Have Been Trying to Deploy the YOLO Model On To Web and Create an API for Inference Purpose... Can You Pls Guide me on this...

@experiencor
Copy link
Owner

@akshaylamba I'm not an expert in deployment but I would use some kind of TensorFLow Serving for this. Alternatively, you may also use Amazon SageMaker. And if you want to run the things entirely in browsers, you may check my other repo https://github.com/experiencor/deeplearnjs.

@KCdreamer
Copy link

Hi, I am trying to reproduce the same results as above but I am unable to do so with the exact same code provided from your repository...... I get something like the attached image.
Thanks for the help in advance!!

screen shot 2018-01-05 at 2 56 30 pm

@experiencor
Copy link
Owner

Things to note to reproduce my result:

  1. Use Full Yolo for the best result.
  2. Should warm the network before actual training. Refer to section 3. Start the training process.
  3. Set train_times to 5 or 10.
  4. (optional) Use gen_anchors.py to generate custom anchors.

Cheers.

@KCdreamer
Copy link

Thank you so much!!!! It is working now!

@KCdreamer
Copy link

I was able to reproduce the raccoon results with Full Yolo, but no luck with Tiny Yolo...
Is there any additional step that I need to do for Tiny Yolo to work?
What I did for Tiny Yolo:

  1. changed architecture to "Tiny Yolo"
  2. did not use any pre-trained weights for warm up, then feed the warmed-up weights as pre-trained weights to do the actual training step (warmup epoch = 0)
  3. used the final resulting weights file to predict boxes... gave me irrelevant boxes :(

I tried using your provided tiny_yolo_raccoon.h5 for prediction and it was great, what should I do get your tiny yolo results?
Thanks again in advance!

@experiencor
Copy link
Owner

It's very tricky to get Tiny Yolo to work given its much less expressive power. You need to play with the 4 scale. Increasing object_scale and coord_scale will help. You may also try the new code to generate anchors (gen_anchors.py).

@KCdreamer
Copy link

Okay, I will try that.
Thank you very much!

@SebastienTs
Copy link

@akshaylamba : Where have you found the multiclass annotations for this data set? Could you share the code you ran to obtain the prediction for these 2 images?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants