experiencor / keras-yolo2

Easy training on custom dataset. Various backends (MobileNet and SqueezeNet) supported. A YOLO demo to detect raccoon run entirely in brower is accessible at https://git.io/vF7vI (not on Windows).
MIT License
1.73k stars 784 forks source link

Quick Questions #9

Closed akshaylamba closed 6 years ago

akshaylamba commented 7 years ago

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 ...

experiencor commented 7 years ago

I'm NOT using Multiscale Training.

Yes, I have the pre-trained weights on VOC data. It's here https://github.com/experiencor/basic-yolo-keras/issues/6.

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

akshaylamba commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

cosmicad commented 7 years ago

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 commented 7 years ago

@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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Ok, sure. I take a look.

experiencor commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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

experiencor commented 6 years ago

@akshaylamba You may try the code suggested in https://github.com/experiencor/basic-yolo-keras/issues/27.

akshaylamba commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

KCdreamer commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

SebastienTs commented 6 years ago

@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?