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 787 forks source link

Relationship between YOLO and MobileNet #329

Open jianing-sun opened 6 years ago

jianing-sun commented 6 years ago

Hi everyone, I have a question about YOLO and MobileNet: If we use MobileNet backend for object detection, then what is the usage of YOLO? My understanding is YOLO is basically a nn structure (darknet19), so is MobileNet. If we chose MobileNet as the network structure, then literally we didn't implement anything about YOLO. Is this correct?

Thanks!

rodrigo2019 commented 6 years ago

YOLO head is different, because YOLO divides the output in a grid, and each cell with N anchors, also the loss function is different, so YOLO is not just an architecture

jpdoiron commented 5 years ago

You can use a pretrained MobileNet (imagenet) for the feature extractor instead of Darknet , but you'll still need the custom loss function for the model to predict bounding box, confidence and classes.

Here's an example I've been using in Keras based on this source : YOLO_ResNet

import keras.applications as ka
mobilenet_model = ka.mobilenetv2.MobileNetV2(weights="imagenet", include_top=False, input_shape = (224,224,3))

model = k.models.Sequential()
model.add(mobilenet_model)
model.add(AveragePooling2D((7, 7), name="avg_pool"))

###------------- YOLO Classifier layer -----------###
model.add(Flatten(name='yolo_clf_0'))
model.add(Dense(2048, activation='relu', name='yolo_clf_1'))
model.add(Dropout(0.5, name="yolo_clf_2"))
model.add(Dense(Grid * Grid* (NumClasses + NumBoundingB * 5), activation="linear", name="yolo_clf_3"))
jianing-sun commented 5 years ago

@jpdoiron Great work! Thanks a lot for your kind reply!

amirunpri2018 commented 4 years ago

You can use a pretrained MobileNet (imagenet) for the feature extractor instead of Darknet , but you'll still need the custom loss function for the model to predict bounding box, confidence and classes.

Here's an example I've been using in Keras based on this source : YOLO_ResNet

import keras.applications as ka
mobilenet_model = ka.mobilenetv2.MobileNetV2(weights="imagenet", include_top=False, input_shape = (224,224,3))

model = k.models.Sequential()
model.add(mobilenet_model)
model.add(AveragePooling2D((7, 7), name="avg_pool"))

###------------- YOLO Classifier layer -----------###
model.add(Flatten(name='yolo_clf_0'))
model.add(Dense(2048, activation='relu', name='yolo_clf_1'))
model.add(Dropout(0.5, name="yolo_clf_2"))
model.add(Dense(Grid * Grid* (NumClasses + NumBoundingB * 5), activation="linear", name="yolo_clf_3"))

Please share code...