allanzelener / YAD2K

YAD2K: Yet Another Darknet 2 Keras
Other
2.72k stars 879 forks source link

Retrain_Yolo issue #28

Open titoghose opened 7 years ago

titoghose commented 7 years ago

@shadySource I tried running your code but due to the variable length of boxes i get an error saying that it expected input of 3 dimensions but got array of size (1,)

alecGraves commented 7 years ago

Where does the error occur?

alecGraves commented 7 years ago

It sounds like the dataset you are using could be in a different format than expected. I would recommend using the following as a guide.

# convert images and image lables to numpy arrays
images = np.asarray(images, dtype=np.uint8)
image_labels = [np.array(boxes) for boxes in image_labels] # list of variable sized arrays
image_labels = np.array(image_labels) # np.object array of variable sized arrays

# save dataset
np.savez("my_data", images=images, boxes=image_labels)

If format was not the issue, perhaps you need to update packages?

titoghose commented 7 years ago

The issue was that I had commented out the portion that was zero padding all my labels to the same length. What is the loss you are getting on training the model on your own dataset? Also how did you decide what the anchors should be? I have found a repository that generates anchors for a dataset but as you trained it on your own dataset I assume you have computed your own anchors?

alecGraves commented 7 years ago

I am getting around 12 on my best validation loss.

I actually didn't figure out the anchors. I do not know what units they are in. I just copied the smallest anchors a couple times because a lot of my data was small circular objects.

That is something I would like to see: a k-means anchor generator for datasets.

titoghose commented 7 years ago

This is a code I found to generate anchors but I'm not sure how to check their validity: https://github.com/Jumabek/darknet_scripts/blob/master/gen_anchors/gen_anchors/gen_anchors.py

titoghose commented 7 years ago

I managed to train the model on my dataset but it ends up over fitting on the training data. Did you face the same issue at any point of time? Also did you train the entire network from scratch or only the last layer?

roshanDD commented 7 years ago

@shadySource

I was following your link to package my dataset http://github.com/shadySource/DATA.

I rewrite a bit to parse a dataset of my own. Here is my own version http://github.com/roshanDD/DATA2

Using the generated .npz file, I ran python retrain_yolo.py, I receive the following error.


(py35) dhcp-6-143:YAD2K-master DiJia$ python retrain_yolo.py 
Using TensorFlow backend.
[array([[b'2', b'1748', b'482', b'1818', b'744']], 
      dtype='|S21'), array([[b'1', b'686', b'566', b'728', b'618']], 
      dtype='|S21'), array([[b'0', b'716', b'578', b'764', b'622']], 
      dtype='|S21'), array([[b'0', b'826', b'580', b'880', b'626']], 
      dtype='|S21'), array([[b'0', b'1540', b'488', b'1680', b'608']], 
      dtype='|S21'), array([[b'0', b'950', b'574', b'1004', b'620']], 
      dtype='|S21'), array([[b'0', b'872', b'586', b'926', b'632']], 
      dtype='|S21')]
Traceback (most recent call last):
  File "retrain_yolo.py", line 349, in <module>
    _main(args)
  File "retrain_yolo.py", line 61, in _main
    image_data, boxes = process_data(data['images'], data['boxes'])
  File "retrain_yolo.py", line 129, in process_data
    boxes_xy = [0.5 * (box[:, 3:5] + box[:, 1:3]) for box in boxes]
  File "retrain_yolo.py", line 129, in <listcomp>
    boxes_xy = [0.5 * (box[:, 3:5] + box[:, 1:3]) for box in boxes]
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('S21') dtype('S21') dtype('S21')

Do you have any ideas why this happen?

alecGraves commented 7 years ago

@roshanDD, It looks like python does not know how to add those datatypes. In your code, try casting your box data to integers.

Change this:

image_labels = [np.array(i[1:]) for i in image_labels]
image_labels = np.array(image_labels)

to this:

image_labels = [np.array(i[1:], dtype=np.uint16) for i in image_labels]
image_labels = np.array(image_labels)
roshanDD commented 7 years ago

@shadySource

Thanks for your reply! I am currently following your approach: 1) package all the image and label into .npz file 2) run retrain_yolo.py to retrain.

However, the problem is that my image data set size is too big. The system rans out of memory on step 1. I am currently running on Amazon AWS machine).

I am wondering what are some possible ways to get around this problem? Thanks!

alecGraves commented 7 years ago

You will probably have to modify the training function to use model.train_on_batch() instead of model.fit().

Also, you should make a loading function for batches of your data. You could load images from a folder and just keep the boxes in memory.

You could also try just separating the images and labels into several .npz files and training on each one, saving the weights and loading them to continue training.

ghost commented 7 years ago

I have been playing with your underwater dataset to see how the training worked. I found that

  1. it was necessary to cast original_size to float otherwise the width and height for each bounding box would be 0

orig_size = np.array([float(images[0].width), float(images[0].height)])

  1. Rather than fine tuning all layers in phase 2/3 simply tune all layers except the first 8 (2 Convolution layers).

You can see the results here, I trained only for ~20 epochs in each phase will train for more now.

https://github.com/AKSHAYUBHAT/DeepVideoAnalytics/blob/master/notebooks/train_yolo.ipynb

ghost commented 7 years ago

Cool could reach as low as ~ 13 val_loss. Where it started detecting start_gate and path_markers (?) correctly.

https://github.com/AKSHAYUBHAT/DeepVideoAnalytics/blob/master/notebooks/train_yolo.ipynb

titoghose commented 7 years ago

@AKSHAYUBHAT how did you decide to freeze the first 8 layers? Is there any particular intuition or did you try multiple combinations? I'm asking because i tried to use your logic on my dataset of traffic signs and symbols and the validation loss gets stuck at 50, and hence the network overfits.

alecGraves commented 7 years ago

@AKSHAYUBHAT Interesting. It is good to know that freezing the beginning layers does not significantly impact performance. It would be good to update the train function to use fewer epochs and not update the first layers.

ghost commented 7 years ago

@shadySource There is a bug in your code when images have different dimensions and the box height width are divided by dimension of first image, it does not appears in the underwater dataset.

See this file, it handles both cases ignoring images with less than 3 channels and dividing bounding box width height by size of that particular frame rather than the 0th frame.

https://github.com/AKSHAYUBHAT/DeepVideoAnalytics/blob/master/dvalib/yolo/trainer.py#L41

roshanDD commented 7 years ago

Just wondering, what is the difference between yolo.h5 vs yolo_topless.h5 ?

How come when I run ./test_yolo.py model_data/yolo_topless.h5

it gives me :

Traceback (most recent call last):
  File "./test_yolo.py", line 194, in <module>
    _main(parser.parse_args())
  File "./test_yolo.py", line 79, in _main
    yolo_model = load_model(model_path)
  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/keras/models.py", line 230, in load_model
    raise ValueError('No model found in config file.')
ValueError: No model found in config file.
chairath commented 7 years ago

Yolo_topless is without the top layer in order to fine tune witht the new added layer.

chairath commented 7 years ago

No model found because in the .h5 file contain only weight , does nt contain the model , so you need to create the model and load_weight . As I understand

roshanDD commented 7 years ago

For the yolo.h5 and the weight download from the quickstart guide from the YAD2k Github page

wget http://pjreddie.com/media/files/yolo.weights
wget https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolo.cfg

screen shot 2017-06-05 at 2 46 20 pm https://pjreddie.com/darknet/yolo/

I am wondering the yolo.h5 downloaded correspond to which one of the model above? Is it YOLOv2 608x608 ?

alecGraves commented 7 years ago

@AKSHAYUBHAT Nice catch, I did not even consider this.

@roshanDD Looking at the links on the page, YLOv2 608x608 corresponds to the URLs in the quickstart guide.

roshanDD commented 7 years ago

@shadySource, thanks for your reply. One more question, for retrain_yolo.py, you remove the final output layer and create another one. I am wondering is it possible not to remove the final output layer? Can we train the Yolo.h5 model with the existing final layer and re-tune it on our dataset?

  if load_pretrained:
        # Save topless yolo:
        topless_yolo_path = os.path.join('model_data', 'yolo_topless.h5')
        if not os.path.exists(topless_yolo_path):
            print("CREATING TOPLESS WEIGHTS FILE")
            yolo_path = os.path.join('model_data', 'yolo.h5')
            model_body = load_model(yolo_path)
            model_body = Model(model_body.inputs, model_body.layers[-2].output)
            model_body.save_weights(topless_yolo_path)
        topless_yolo.load_weights(topless_yolo_path)

    if freeze_body:
        for layer in topless_yolo.layers:
            layer.trainable = False
    final_layer = Conv2D(len(anchors)*(5+len(class_names)), (1, 1), activation='linear')(topless_yolo.output)

    model_body = Model(image_input, final_layer)
alecGraves commented 7 years ago

@roshanDD The final layer is removed because the outputs of the final layer correspond to things specific to a dataset such as the number of possible classes and the number of anchor boxes used. You can use the same output layer if your dataset predicts the same number of classes and uses the same number of anchor boxes.

roshanDD commented 7 years ago

@shadySource

Thanks for your reply. I am currently using yolo-voc, which has a default of 20 class. However, I am only interested in classifying 1 class (people).

I found removing the last layer, and then add another one not very accurate. On the other hand, if I simply train the existing model (without removing the last layer), it looks like the parameters are too big.

Is there any way for me to use the existing model (without removing the last layer), and also only predict 1 class?

If I can do that, how many layers should I open (I guess it would be the last 3, since conv2d_22 has 10000000 parameters)?

____________________________________________________________________________________________________
Layer (type)                     Output Shape          Param #     Connected to                     
====================================================================================================
input_1 (InputLayer)             (None, 416, 416, 3)   0                                            
____________________________________________________________________________________________________
conv2d_1 (Conv2D)                (None, 416, 416, 32)  864                                          
____________________________________________________________________________________________________
batch_normalization_1 (BatchNorm (None, 416, 416, 32)  128                                          
____________________________________________________________________________________________________
leaky_re_lu_1 (LeakyReLU)        (None, 416, 416, 32)  0                                            
____________________________________________________________________________________________________
max_pooling2d_1 (MaxPooling2D)   (None, 208, 208, 32)  0                                            
____________________________________________________________________________________________________
conv2d_2 (Conv2D)                (None, 208, 208, 64)  18432                                        
____________________________________________________________________________________________________
batch_normalization_2 (BatchNorm (None, 208, 208, 64)  256                                          
____________________________________________________________________________________________________
leaky_re_lu_2 (LeakyReLU)        (None, 208, 208, 64)  0                                            
____________________________________________________________________________________________________
max_pooling2d_2 (MaxPooling2D)   (None, 104, 104, 64)  0                                            
____________________________________________________________________________________________________
conv2d_3 (Conv2D)                (None, 104, 104, 128) 73728                                        
____________________________________________________________________________________________________
batch_normalization_3 (BatchNorm (None, 104, 104, 128) 512                                          
____________________________________________________________________________________________________
leaky_re_lu_3 (LeakyReLU)        (None, 104, 104, 128) 0                                            
____________________________________________________________________________________________________
conv2d_4 (Conv2D)                (None, 104, 104, 64)  8192                                         
____________________________________________________________________________________________________
batch_normalization_4 (BatchNorm (None, 104, 104, 64)  256                                          
____________________________________________________________________________________________________
leaky_re_lu_4 (LeakyReLU)        (None, 104, 104, 64)  0                                            
____________________________________________________________________________________________________
conv2d_5 (Conv2D)                (None, 104, 104, 128) 73728                                        
____________________________________________________________________________________________________
batch_normalization_5 (BatchNorm (None, 104, 104, 128) 512                                          
____________________________________________________________________________________________________
leaky_re_lu_5 (LeakyReLU)        (None, 104, 104, 128) 0                                            
____________________________________________________________________________________________________
max_pooling2d_3 (MaxPooling2D)   (None, 52, 52, 128)   0                                            
____________________________________________________________________________________________________
conv2d_6 (Conv2D)                (None, 52, 52, 256)   294912                                       
____________________________________________________________________________________________________
batch_normalization_6 (BatchNorm (None, 52, 52, 256)   1024                                         
____________________________________________________________________________________________________
leaky_re_lu_6 (LeakyReLU)        (None, 52, 52, 256)   0                                            
____________________________________________________________________________________________________
conv2d_7 (Conv2D)                (None, 52, 52, 128)   32768                                        
____________________________________________________________________________________________________
batch_normalization_7 (BatchNorm (None, 52, 52, 128)   512                                          
____________________________________________________________________________________________________
leaky_re_lu_7 (LeakyReLU)        (None, 52, 52, 128)   0                                            
____________________________________________________________________________________________________
conv2d_8 (Conv2D)                (None, 52, 52, 256)   294912                                       
____________________________________________________________________________________________________
batch_normalization_8 (BatchNorm (None, 52, 52, 256)   1024                                         
____________________________________________________________________________________________________
leaky_re_lu_8 (LeakyReLU)        (None, 52, 52, 256)   0                                            
____________________________________________________________________________________________________
max_pooling2d_4 (MaxPooling2D)   (None, 26, 26, 256)   0                                            
____________________________________________________________________________________________________
conv2d_9 (Conv2D)                (None, 26, 26, 512)   1179648                                      
____________________________________________________________________________________________________
batch_normalization_9 (BatchNorm (None, 26, 26, 512)   2048                                         
____________________________________________________________________________________________________
leaky_re_lu_9 (LeakyReLU)        (None, 26, 26, 512)   0                                            
____________________________________________________________________________________________________
conv2d_10 (Conv2D)               (None, 26, 26, 256)   131072                                       
____________________________________________________________________________________________________
batch_normalization_10 (BatchNor (None, 26, 26, 256)   1024                                         
____________________________________________________________________________________________________
leaky_re_lu_10 (LeakyReLU)       (None, 26, 26, 256)   0                                            
____________________________________________________________________________________________________
conv2d_11 (Conv2D)               (None, 26, 26, 512)   1179648                                      
____________________________________________________________________________________________________
batch_normalization_11 (BatchNor (None, 26, 26, 512)   2048                                         
____________________________________________________________________________________________________
leaky_re_lu_11 (LeakyReLU)       (None, 26, 26, 512)   0                                            
____________________________________________________________________________________________________
conv2d_12 (Conv2D)               (None, 26, 26, 256)   131072                                       
____________________________________________________________________________________________________
batch_normalization_12 (BatchNor (None, 26, 26, 256)   1024                                         
____________________________________________________________________________________________________
leaky_re_lu_12 (LeakyReLU)       (None, 26, 26, 256)   0                                            
____________________________________________________________________________________________________
conv2d_13 (Conv2D)               (None, 26, 26, 512)   1179648                                      
____________________________________________________________________________________________________
batch_normalization_13 (BatchNor (None, 26, 26, 512)   2048                                         
____________________________________________________________________________________________________
leaky_re_lu_13 (LeakyReLU)       (None, 26, 26, 512)   0                                            
____________________________________________________________________________________________________
max_pooling2d_5 (MaxPooling2D)   (None, 13, 13, 512)   0                                            
____________________________________________________________________________________________________
conv2d_14 (Conv2D)               (None, 13, 13, 1024)  4718592                                      
____________________________________________________________________________________________________
batch_normalization_14 (BatchNor (None, 13, 13, 1024)  4096                                         
____________________________________________________________________________________________________
leaky_re_lu_14 (LeakyReLU)       (None, 13, 13, 1024)  0                                            
____________________________________________________________________________________________________
conv2d_15 (Conv2D)               (None, 13, 13, 512)   524288                                       
____________________________________________________________________________________________________
batch_normalization_15 (BatchNor (None, 13, 13, 512)   2048                                         
____________________________________________________________________________________________________
leaky_re_lu_15 (LeakyReLU)       (None, 13, 13, 512)   0                                            
____________________________________________________________________________________________________
conv2d_16 (Conv2D)               (None, 13, 13, 1024)  4718592                                      
____________________________________________________________________________________________________
batch_normalization_16 (BatchNor (None, 13, 13, 1024)  4096                                         
____________________________________________________________________________________________________
leaky_re_lu_16 (LeakyReLU)       (None, 13, 13, 1024)  0                                            
____________________________________________________________________________________________________
conv2d_17 (Conv2D)               (None, 13, 13, 512)   524288                                       
____________________________________________________________________________________________________
batch_normalization_17 (BatchNor (None, 13, 13, 512)   2048                                         
____________________________________________________________________________________________________
leaky_re_lu_17 (LeakyReLU)       (None, 13, 13, 512)   0                                            
____________________________________________________________________________________________________
conv2d_18 (Conv2D)               (None, 13, 13, 1024)  4718592                                      
____________________________________________________________________________________________________
batch_normalization_18 (BatchNor (None, 13, 13, 1024)  4096                                         
____________________________________________________________________________________________________
leaky_re_lu_18 (LeakyReLU)       (None, 13, 13, 1024)  0                                            
____________________________________________________________________________________________________
conv2d_19 (Conv2D)               (None, 13, 13, 1024)  9437184                                      
____________________________________________________________________________________________________
batch_normalization_19 (BatchNor (None, 13, 13, 1024)  4096                                         
____________________________________________________________________________________________________
conv2d_21 (Conv2D)               (None, 26, 26, 64)    32768                                        
____________________________________________________________________________________________________
leaky_re_lu_19 (LeakyReLU)       (None, 13, 13, 1024)  0                                            
____________________________________________________________________________________________________
batch_normalization_21 (BatchNor (None, 26, 26, 64)    256                                          
____________________________________________________________________________________________________
conv2d_20 (Conv2D)               (None, 13, 13, 1024)  9437184                                      
____________________________________________________________________________________________________
leaky_re_lu_21 (LeakyReLU)       (None, 26, 26, 64)    0                                            
____________________________________________________________________________________________________
batch_normalization_20 (BatchNor (None, 13, 13, 1024)  4096                                         
____________________________________________________________________________________________________
space_to_depth (Lambda)          (None, 13, 13, 256)   0                                            
____________________________________________________________________________________________________
leaky_re_lu_20 (LeakyReLU)       (None, 13, 13, 1024)  0                                            
____________________________________________________________________________________________________
concatenate_1 (Concatenate)      (None, 13, 13, 1280)  0                                            
____________________________________________________________________________________________________
conv2d_22 (Conv2D)               (None, 13, 13, 1024)  11796480                                     
____________________________________________________________________________________________________
batch_normalization_22 (BatchNor (None, 13, 13, 1024)  4096                                         
____________________________________________________________________________________________________
leaky_re_lu_22 (LeakyReLU)       (None, 13, 13, 1024)  0                                            
____________________________________________________________________________________________________
conv2d_23 (Conv2D)               (None, 13, 13, 125)   128125                                       
====================================================================================================
jayakrishna-a commented 7 years ago

@roshanDD. I am also trying the same using retrain_yolo.py script. First I converted model from yolo to keras using yad2k.py script. I am trying to use the same model for one class problem. But when I am trying to load the model in retrain_yolo.py script, I am getting error in load_model function. Following is the error

In ..../keras/kutila/generic_utils.py line 202, in func_load

Code = marshal.loads(code.encode('raw_unicode_escape'))

ValueError: bad marshal data (unknown type code)

Can anyone please help regarding this.

Tangzy7 commented 7 years ago

@shadySource Hi, I cannot figure out why retrain_yolo.py train and save the model three times. And did you try to retrain on Pascal and get a result closed to benchmark?

model.fit([image_data, boxes, detectors_mask, matching_true_boxes],
          np.zeros(len(image_data)),
          validation_split=validation_split,
          batch_size=32,
          epochs=5,
          callbacks=[logging])
model.save_weights('trained_stage_1.h5')

model_body, model = create_model(anchors, class_names, load_pretrained=False, freeze_body=False)

model.load_weights('trained_stage_1.h5')

model.compile(
    optimizer='adam', loss={
        'yolo_loss': lambda y_true, y_pred: y_pred
    })  # This is a hack to use the custom loss function in the last layer.

model.fit([image_data, boxes, detectors_mask, matching_true_boxes],
          np.zeros(len(image_data)),
          validation_split=0.1,
          batch_size=8,
          epochs=30,
          callbacks=[logging])

model.save_weights('trained_stage_2.h5')

model.fit([image_data, boxes, detectors_mask, matching_true_boxes],
          np.zeros(len(image_data)),
          validation_split=0.1,
          batch_size=8,
          epochs=30,
          callbacks=[logging, checkpoint, early_stopping])

model.save_weights('trained_stage_3.h5')
ghost commented 7 years ago

@Tangzy7 First it finetunes only the last layer, next it tunes all layers since it need not save weights at end of each epoch it runs without early stopping and checkpointing, finally it runs with checkpoint and early stopping to stop as soon as val loss starts increasing.

zaoyang commented 7 years ago

@roshanDD @shadySource

I followed your advice for your underwater dataset. I'm just trying to get it to work. I cloned DATA and then I changed this: image_labels = [np.array(i[1:], dtype=np.uint16) for i in image_labels] image_labels = np.array(image_labels)

Still get this. Any ideas?

Using TensorFlow backend. Traceback (most recent call last): File "retrain_yolo.py", line 345, in _main(args) File "retrain_yolo.py", line 60, in _main image_data, boxes = process_data(data['images'], data['boxes']) File "retrain_yolo.py", line 125, in process_data boxes_xy = [0.5 * (box[:, 3:5] + box[:, 1:3]) for box in boxes]

File "retrain_yolo.py", line 125, in boxes_xy = [0.5 * (box[:, 3:5] + box[:, 1:3]) for box in boxes] TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('S21') dtype('S21') dtype('S21')

Tangzy7 commented 7 years ago

@AKSHAYUBHAT Thanks! But I am still confused that why we need to fix the base layers and train the last layer at first stage?

By the way, I tried to train on voc2007+2012 but the training ended in 60 val_loss for a 8 validation batch size. It means that each sample got a loss of 8(I found that the loss wasn't divided by batch size in both paper and code). It seems that the loss cannot coverage in VOC. Did you recurrent the result of the paper?

ghost commented 7 years ago

@Tangzy7 The correct approach would be to calculate MAP score and compare with the one reported in the paper, I am not sure what is the lowest loss achieved by the model, and it most certainly won't be zero since the model always makes few errors.

roshanDD commented 7 years ago

I am wondering for the true_areas = true_wh[..., 0] * true_wh[..., 1] in the yolo loss, https://github.com/allanzelener/YAD2K/blob/master/yad2k/models/keras_yolo.py#L244

It's print as [[[[[0.0010607638]]]][[[[0.0022916668]]]][[[[0.0027604166]]]][[[[0.0017135417]]]][[[[0.001388889]]]][[[[0.0012690972]]]][[[[0.0034236112]]]][[[[0.0018750001]]]]]

I am wondering how come it has 8 dimensions and what does each dimension represent? @AKSHAYUBHAT @shadySource

Tangzy7 commented 7 years ago

@shadySource @allanzelener Hi, I am wondering whether the loss have some bug. I did two experiments. I converted the official weight from yolov2 website to h5 file, and used retrain.py to test the loss. I loaded the weights and unfroze the all the layers at first and output the loss. I saw the loss is 54 at first iteration but it increase from 2nd iteration. Epoch 1/5 1/345 [..............................] - ETA: 2681s - loss: 54.8437 2/345 [..............................] - ETA: 1736s - loss: 533.8541 3/345 [..............................] - ETA: 1418s - loss: 885.0294 4/345 [..............................] - ETA: 1257s - loss: 756.5366 5/345 [..............................] - ETA: 1159s - loss: 677.7412

Then I froze all layers and trained the model again. The loss is stable. Epoch 1/5 1/345 [..............................] - ETA: 1241s - loss: 73.1654 2/345 [..............................] - ETA: 769s - loss: 59.7281 3/345 [..............................] - ETA: 611s - loss: 74.8418 4/345 [..............................] - ETA: 532s - loss: 67.1894

Later I just found that the loss function in script didn't use the square root of W and H to calculate the loss. Are you meant to do that? I am still retraining on voc.

jayakrishna-a commented 7 years ago

Hi,

I modified retrain_yolo.py and able to train only last layer for single class output. I ran around 65 epochs. The weights converged to around 6.5 but the prediction is completely wrong. I gave input od size 416×416 images and their corresponding boxes for training. Most of the time in testing did not find any boxes. Even if it is found the boxes are in wrong locations. Can anyone help in this regard?

dgorissen commented 7 years ago

@jayakrishna-a I just ran into the same bad marshal data error you ran into (model exports fine, failing on load), how did you fix this?

alecGraves commented 7 years ago

@dgorissen I ran into that issue a few days ago. I believe I solved it by creating the model then loading the weights separately.

dgorissen commented 7 years ago

@shadySource Thanks, I did actually try that (load model & weights separately). I was trying to load the model (exported in python 3) in a python 2 environment, assuming the serialisation would be compatible. Switching to python 3 on loading side made the problem go away. Unfortunately it then fails a few lines further with ValueError: You are trying to load a weight file containing 42 layers into a model with 44 layers when trying to load the weights into the topless model. The converted yolo.h5 itself seems good (runs fine on some test images). Whack-a-mole continues..

Edit: I was using yolo.weights and yolo.cfg from the darkflow repo, figuring they were the same. Turns out they actually define a slightly larger network. Eval'ing works but trying to retrain gives the error above. Switched to the weights/cfg from the darknet site and now it works as expected.

Firyuza commented 7 years ago

After retraining it saves only weights. But how can I create model and load these weights? Thanks.

ldocao commented 6 years ago

@dgorissen is this related to your problem ? https://forums.developer.apple.com/thread/82045

wizholy commented 6 years ago

@AKSHAYUBHAT the link is missed, can you shared it again? https://github.com/AKSHAYUBHAT/DeepVideoAnalytics/blob/master/notebooks/train_yolo.ipynb

dhirajsangwan commented 6 years ago

@ AKSHAYUBHAT kindly share the following link of retraining yad2k on custom dataset again as it is not available now https://github.com/AKSHAYUBHAT/DeepVideoAnalytics/blob/master/notebooks/train_yolo.ipynb

arvindhbti commented 6 years ago

Hey brother im facing this issue when converting to yolo.h5 model.

Layer (type) Output Shape Param # Connected to input_1 (InputLayer) (None, None, None, 3 0 conv2d_1 (Conv2D) (None, None, None, 3 864 input_1[0][0] batch_normalization_1 (BatchNor (None, None, None, 3 128 conv2d_1[0][0] leaky_re_lu_1 (LeakyReLU) (None, None, None, 3 0 batch_normalization_1[0][0] max_pooling2d_1 (MaxPooling2D) (None, None, None, 3 0 leaky_re_lu_1[0][0] conv2d_2 (Conv2D) (None, None, None, 6 18432 max_pooling2d_1[0][0] batch_normalization_2 (BatchNor (None, None, None, 6 256 conv2d_2[0][0] leaky_re_lu_2 (LeakyReLU) (None, None, None, 6 0 batch_normalization_2[0][0] max_pooling2d_2 (MaxPooling2D) (None, None, None, 6 0 leaky_re_lu_2[0][0] conv2d_3 (Conv2D) (None, None, None, 1 73728 max_pooling2d_2[0][0] batch_normalization_3 (BatchNor (None, None, None, 1 512 conv2d_3[0][0] leaky_re_lu_3 (LeakyReLU) (None, None, None, 1 0 batch_normalization_3[0][0] conv2d_4 (Conv2D) (None, None, None, 6 8192 leaky_re_lu_3[0][0] batch_normalization_4 (BatchNor (None, None, None, 6 256 conv2d_4[0][0] leaky_re_lu_4 (LeakyReLU) (None, None, None, 6 0 batch_normalization_4[0][0] conv2d_5 (Conv2D) (None, None, None, 1 73728 leaky_re_lu_4[0][0] batch_normalization_5 (BatchNor (None, None, None, 1 512 conv2d_5[0][0] leaky_re_lu_5 (LeakyReLU) (None, None, None, 1 0 batch_normalization_5[0][0] max_pooling2d_3 (MaxPooling2D) (None, None, None, 1 0 leaky_re_lu_5[0][0] conv2d_6 (Conv2D) (None, None, None, 2 294912 max_pooling2d_3[0][0] batch_normalization_6 (BatchNor (None, None, None, 2 1024 conv2d_6[0][0] leaky_re_lu_6 (LeakyReLU) (None, None, None, 2 0 batch_normalization_6[0][0] conv2d_7 (Conv2D) (None, None, None, 1 32768 leaky_re_lu_6[0][0] batch_normalization_7 (BatchNor (None, None, None, 1 512 conv2d_7[0][0] leaky_re_lu_7 (LeakyReLU) (None, None, None, 1 0 batch_normalization_7[0][0] conv2d_8 (Conv2D) (None, None, None, 2 294912 leaky_re_lu_7[0][0] batch_normalization_8 (BatchNor (None, None, None, 2 1024 conv2d_8[0][0] leaky_re_lu_8 (LeakyReLU) (None, None, None, 2 0 batch_normalization_8[0][0] max_pooling2d_4 (MaxPooling2D) (None, None, None, 2 0 leaky_re_lu_8[0][0] conv2d_9 (Conv2D) (None, None, None, 5 1179648 max_pooling2d_4[0][0] batch_normalization_9 (BatchNor (None, None, None, 5 2048 conv2d_9[0][0] leaky_re_lu_9 (LeakyReLU) (None, None, None, 5 0 batch_normalization_9[0][0] conv2d_10 (Conv2D) (None, None, None, 2 131072 leaky_re_lu_9[0][0] batch_normalization_10 (BatchNo (None, None, None, 2 1024 conv2d_10[0][0] leaky_re_lu_10 (LeakyReLU) (None, None, None, 2 0 batch_normalization_10[0][0] conv2d_11 (Conv2D) (None, None, None, 5 1179648 leaky_re_lu_10[0][0] batch_normalization_11 (BatchNo (None, None, None, 5 2048 conv2d_11[0][0] leaky_re_lu_11 (LeakyReLU) (None, None, None, 5 0 batch_normalization_11[0][0] conv2d_12 (Conv2D) (None, None, None, 2 131072 leaky_re_lu_11[0][0] batch_normalization_12 (BatchNo (None, None, None, 2 1024 conv2d_12[0][0] leaky_re_lu_12 (LeakyReLU) (None, None, None, 2 0 batch_normalization_12[0][0] conv2d_13 (Conv2D) (None, None, None, 5 1179648 leaky_re_lu_12[0][0] batch_normalization_13 (BatchNo (None, None, None, 5 2048 conv2d_13[0][0]

how to fix it?? please help me out.

cyrineee commented 5 years ago

when i run the command : ./test_yolo.py model_data/yolo.h5 from : https://github.com/allanzelener/YAD2K it shows this github