Giter VIP home page Giter VIP logo

yolov5-tf's Introduction

YOLOv5 implementation using TensorFlow 2

Train

  • Change data_dir, image_dir, label_dir and class_dict in config.py
  • Choose version in config.py
  • Optional, python main.py --anchor to generate anchors for your dataset and change anchors in config.py
  • Optional, python main.py --record to generate tf-record for your dataset
  • Run python main.py --train for training

Test

  • Run python main.py --test

Dataset structure

├── Dataset folder 
    ├── images
        ├── 1111.jpg
        ├── 2222.jpg
    ├── labels
        ├── 1111.xml
        ├── 2222.xml
    ├── train.txt
    ├── test.txt

Note

  • xml file should be in PascalVOC format
  • train.txt test.txt contains image names without extension

Recommendation (for docker users)

  • docker pull nvcr.io/nvidia/tensorflow:20.12-tf2-py3
  • nvidia-docker run --gpus all -v /your/project/folder:/Projects -it nvcr.io/nvidia/tensorflow:20.12-tf2-py3
  • cd ../Projects
  • apt-get update
  • apt-get install ffmpeg libsm6 libxext6 -y
  • pip install opencv-python

Reference

yolov5-tf's People

Contributors

jahongir7174 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

yolov5-tf's Issues

Dimensions must be equal, but are 2 and 0 for '{{node mul_1}} = Mul[T=DT_FLOAT](Exp, mul_1/y)' with input shapes: [32,20,20,3,2], [0].

Traceback (most recent call last):
File "/home/x/PycharmProjects/YOLOv5-tf-master/main.py", line 280, in
train()
File "/home/x/PycharmProjects/YOLOv5-tf-master/main.py", line 91, in train
train_fn()
File "/home/x/PycharmProjects/YOLOv5-tf-master/main.py", line 84, in train_fn
loss = distributed_train_step(image, y_true)
File "/usr/local/python3/lib/python3.9/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/usr/local/python3/lib/python3.9/site-packages/tensorflow/python/framework/func_graph.py", line 1129, in autograph_handler
raise e.ag_error_metadata.to_exception(e)
ValueError: in user code:

File "/home/x/PycharmProjects/YOLOv5-tf-master/main.py", line 69, in distributed_train_step  *
    per_replica_losses = strategy.run(train_step, args=(image, y_true))
File "/home/x/PycharmProjects/YOLOv5-tf-master/main.py", line 60, in train_step  *
    loss = compute_loss(y_true, y_pred)
File "/home/x/PycharmProjects/YOLOv5-tf-master/main.py", line 53, in compute_loss  *
    total_loss = loss_object(y_pred, y_true)
File "/home/x/PycharmProjects/YOLOv5-tf-master/nets/nn.py", line 271, in __call__  *
    loss += self.compute_loss(y_pred[i], y_true[i], anchor_group[i])
File "/home/x/PycharmProjects/YOLOv5-tf-master/nets/nn.py", line 217, in compute_loss  *
    x_y_offset, pred_boxes, pred_conf, pred_prob = process_layer(y_pred, anchors)
File "/home/x/PycharmProjects/YOLOv5-tf-master/nets/nn.py", line 130, in process_layer  *
    box_sizes = tf.exp(box_sizes) * rescaled_anchors

ValueError: Dimensions must be equal, but are 2 and 0 for '{{node mul_1}} = Mul[T=DT_FLOAT](Exp, mul_1/y)' with input shapes: [32,20,20,3,2], [0].

width and depth parameters in the config.py

Hello, Firstly, thank you for making this repo public.
Can you explain the height and the width parameters in the config.py? What do they represent?
Also, how did you choose the constant values for them?
Thanks

I have a question about Train, Test.

When training, try with the file below.
-IMAGES, LABELS, train.txt
When testing, try with the following file.
-IMAGES, val.txt

In general, training is classified into three categories: Training set, Validation set, and Test set.
Is YOLOv5 configured as follows?
Train = Training set + Validation set
Test = Test set
In the case of Train, is the training set and validation set automatically classified and trained?
If this is correct, what is the ratio?

bug report about util.resize

Hello,jahongir7174.

util.resize returns image_padded, scale, dw, dh.

However, in test.py, at about line 46, image_np, dw, dh, scale = util.resize(image_np).

Please fix the bug. Thanks for your job again.

Model performance

Dear @jahongir7174 ,

Thanks for sharing your work.

I am curious about how your train models performance compared to the pytorch version?

Overlapping

How should I solve the problem of bounding box overlapping?
I tried the non_max_suppression function, but it seems not work.

Can you provide an example of dataset structure?

Hi, I'm new to AI and I'm trying to make train my own dataset but i have difficulties understanding how to organize and label data.
Can you actually create the "Dataset folder" with a couple of images (and related train.txt, etc) inside that I can use as example?
Thant way I think will be able change my data as per your project structure.
Thanks!

Lack of other versions

Hello, thanks for your sharing of your work.

In pytorch version, there are four versions: s, m, l, x.

By viewing your code, I guess your network is yolov5x.

Do you have plans of updating the other version like s?

Thanks a lot

IndexError

Hello,

At first, thank you for making this repository open source, great work.
The algorithm seems to work on most of the datasets that I have tried without any problems.
However, on one particular dataset(which is bigger but very similar to the others), I get an error,

image, boxes = util.resize(image, boxes)
File "/home/usr/yolo/YOLOv5-tf/utils/util.py", line 55, in resize
boxes[:, [0, 2]] = boxes[:, [0, 2]] * scale + dw
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

I cant for the life of me debug this, the shapes seem to be consistent.
I understand that this might not be enough information for you to work with but I was just wondering if you have ever had this kind of a problem.

Thanks in advance.

ValueError: Duplicate node name in graph: 'ones'

Thank you for all the work you have done on this code. We have enjoyed using it. The training has worked fine for us, but we got the error in the title during testing. This may have to do with tensorflow versions (we are using 2.1.0). There is a thread on this same error on tensorflow/tensorflow#43534, but it is not clear if the error was resolved.

In your code it happens on this line in process_layer:

grid_x, grid_y = tf.meshgrid(grid_x, grid_y)

which then leads to this line in array_ops:

mult_fact = ones(shapes, output_dtype)

But the error only happens when process_layer is called from predict (during testing), but not when called from process_loss (during training).

Do you have any suggestions for us? I am including the full error traceback below.

Thanks.

Traceback (most recent call last):
File "/home/martin/.pycharm_helpers/pydev/pydevd.py", line 1741, in
main()
File "/home/martin/.pycharm_helpers/pydev/pydevd.py", line 1735, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/home/martin/.pycharm_helpers/pydev/pydevd.py", line 1135, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/home/martin/.pycharm_helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/media/martin/Storage/Kaggle/ChestXray/YOLOv5/test_new.py", line 90, in
main()
File "/media/martin/Storage/Kaggle/ChestXray/YOLOv5/test_new.py", line 69, in main
model = nn.build_model(training=False)
File "/media/martin/Storage/Kaggle/ChestXray/YOLOv5/nets/nn.py", line 103, in build_model
return tf.keras.Model(inputs, predict([p5, p4, p3]))
File "/media/martin/Storage/Kaggle/ChestXray/YOLOv5/nets/nn.py", line 150, in predict
reorg_results = [process_layer(feature_map, anchors) for (feature_map, anchors) in feature_map_anchors]
File "/media/martin/Storage/Kaggle/ChestXray/YOLOv5/nets/nn.py", line 150, in
reorg_results = [process_layer(feature_map, anchors) for (feature_map, anchors) in feature_map_anchors]
File "/media/martin/Storage/Kaggle/ChestXray/YOLOv5/nets/nn.py", line 118, in process_layer
grid_x, grid_y = tf.meshgrid(grid_x, grid_y)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/array_ops.py", line 3065, in meshgrid
mult_fact = ones(shapes, output_dtype)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/array_ops.py", line 2671, in ones
output = fill(shape, constant(one, dtype=dtype), name=name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/array_ops.py", line 233, in fill
result = gen_array_ops.fill(dims, value, name=name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/gen_array_ops.py", line 3247, in fill
"Fill", dims=dims, value=value, name=name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/op_def_library.py", line 742, in _apply_op_helper
attrs=attr_protos, op_def=op_def)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/func_graph.py", line 595, in _create_op_internal
compute_device)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py", line 3322, in _create_op_internal
op_def=op_def)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py", line 1786, in init
control_input_ops)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py", line 1622, in _create_c_op
raise ValueError(str(e))
ValueError: Duplicate node name in graph: 'ones'

boudingbox no detect

I trained the network in 100 times and the model was generated perfectly, but during the tests the boundign boxes were not detected

some issue

It works well, but sometimes it freezes and doesn't work.
It is displayed and stops as shown in the execution log below. And it cannot create the TF folder.
However, it works normally after a few attempts. Do you have any idea of a solution to the issue?

Execution log
mcrc-ml@mcrcml-DGX-Station:~/workspace/cslee/YOLOv5-tf$ python generate.py
2021-02-04 17:41:11.943521: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
/home/mcrc-ml/anaconda3/envs/tf230/lib/python3.8/site-packages/numpy/core/fromnumeric.py:3334: RuntimeWarning: Mean of empty slice.
return _methods._mean(a, axis=axis, dtype=dtype,
/home/mcrc-ml/anaconda3/envs/tf230/lib/python3.8/site-packages/numpy/core/_methods.py:153: RuntimeWarning: invalid value encountered in true_divide
ret = um.true_divide(

test error

Hello! your work is very good!

I'm having an error running the test.

follow the log to view

/home/fredson/YOLOv5-tf-master/nets/nn.py:324 call  *
    outputs = tf.map_fn(fn=compute_nms,
/home/fredson/YOLOv5-tf-master/nets/nn.py:165 nms_fn  *
    score_indices = tf.where(backend.greater(score, config.threshold))

AttributeError: module 'utils.config' has no attribute 'threshold'`

Can't generate anchors

I'm trying to train my dataset using this repo, but I'm facing errors in the anchors generating process:

Traceback (most recent call last):
  File "generate.py", line 84, in <module>
    generator.generate_anchor()
  File "generate.py", line 59, in generate_anchor
    boxes = self.get_boxes()
  File "generate.py", line 73, in get_boxes
    y_min = annotation[1]
IndexError: index 1 is out of bounds for axis 0 with size 1

This is a sample of annotation file (.xml):

	<folder>train</folder>
	<filename>20201003140922.png</filename>
	<path>D:\Projects\datasets\kings\train\20201003140922.png</path>
	<source>
		<database>Unknown</database>
	</source>
	<size>
		<width>800</width>
		<height>600</height>
		<depth>3</depth>
	</size>
	<segmented>0</segmented>
	<object>
		<name>king</name>
		<pose>Unspecified</pose>
		<truncated>0</truncated>
		<difficult>0</difficult>
		<bndbox>
			<xmin>202</xmin>
			<ymin>216</ymin>
			<xmax>469</xmax>
			<ymax>527</ymax>
		</bndbox>
	</object>
</annotation>

some issues about generate.py

hello jahongir.thanks you code.But something went wrong when I used it。when i run generate.py,it work good but just generate anchors no tf and Anything else。
K anchors: [[ 9. 9.] [ 15. 15.] [ 19. 21.] [ 24. 32.] [ 26. 25.] [ 33. 35.] [ 44. 48.] [ 62. 77.] [105. 165.]] Accuracy: 77.75%

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.