xiaochus / YOLOv3

Keras implementation of yolo v3 object detection.
MIT License
605 stars 264 forks source link

Creating the net without yolov3.weights makes it untrainable #10

Closed altvali closed 6 years ago

altvali commented 6 years ago

Hello,

I'm trying to train a network for different tasks, based on your project. The main issue I have is that if I create the same net with random weights instead of those from yolov3.weights (using this script: https://pastebin.com/RECciwrs) I get a net with the same number of params, the same layers, but on inference it outputs a matrix of NaNs. Since it outputs NaNs, I cannot train it, it will not converge to the desired weights.

How to repro:

  1. Save the script from https://pastebin.com/RECciwrs as create_yolo_from_scratch.py
  2. python yad2k.py cfg\yolo.cfg yolov3.weights data\yolo.h5
  3. python create_yolo_from_scratch.py cfg/yolo.cfg yolo_random_weights.h5
  4. For convenience, resize giraffe.jpg to 416x416 and rename as giraffe416.jpg
  5. Run in terminal: python
    from keras.models import load_model
    import numpy as np
    import cv2
    yolo = load_model('yolo.h5')
    yolo_rw = load_model('yolo_random_weights.h5')
    path = 'images/test/giraffe416.jpg'
    image = cv2.imread(path)
    image = np.array(image, dtype='float32')
    image /= 255.
    image = np.expand_dims(image, axis=0)
    yolo.predict(image)
    # will output a matrix of numbers
    yolo_rw.predict(image)
    # will output a matrix of NaNs
    yolo_rw.set_weights(yolo.get_weights())
    yolo_rw.predict(image)
    # will output a matrix of numbers

Without using yolov3.weights, do you have any advice on how to seed the network so that it's trainable? I want to then use a different config file for a different number of classes in order to train. Thank you.

altvali commented 6 years ago

Nevermind, it was an issue with my Tensorflow installation.