I followed this tutorial for training object detection model on coco dataset. The tutorial contains a step to download and use coco dataset and its annotations and convert them to TFRecord.
I need to use my own custom data to train, i annotated using labelimg tool which produced xml files containing (w,h,xmin,ymin,xmax,ymax) for images.
But coco dataset has JSON format with Image segmentation fields for creating a TFRecord.
Is segmentation mandatory for training resnet, retinanet?
So, can anyone guide me a procedure for creating a JSON annotation from my XML annotations without segmentation values?
xml:
<annotation>
<folder>frames</folder>
<filename>83.jpg</filename>
<path>/home/tdadmin/Downloads/large/f/frames/83.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>640</width>
<height>480</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>person</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>246</xmin>
<ymin>48</ymin>
<xmax>350</xmax>
<ymax>165</ymax>
</bndbox>
</object>
</annotation>
What you are doing now is kind of similar to a project I've done before. So I have some suggestions for you.
When I was training my Mask RCNN model, I used VGG Image Annotator (you can easily find that on Google). By using that tool, it's easy to create json annotation files. Then plug that in your training.
Hope that would help you. Feel free to comment on this if you still have questions.
Rowen
The annotation format actually doesn't matter. I have myself created tfrecord from txt files before. To create custom tfrecord you would have to write your own create_custom_tf_record.py just as others shown in this folder.
But since you are using coco similar annotations, you can make use of the file create_coco_tf_record.py. The important thing you need to implement yourself is the annotations_list. The annotations_list is just a dictionary so your goal is to parse your xml file into a dictionary containing key value pairs, and then pass the correct value to the feature_dict, then construct tf.train.Example from the feature_dict. Once you have the tf.train.Example created, you can create tfrecord easily.
So for your exact example, first parse the xml file.
import xml.etree.ElementTree as ET
tree = ET.parse('annotations.xml')
Then construct annotaions_list from tree like this:
annotations_list = {}
it = tree.iter()
for key in it:
annotations_list[str(key.tag)] = key.text
Then you can create the feature_dict from the annotations_list
feature_dict = {
'image/height':
dataset_util.int64_feature(annotatios_list['height']),
'image/width':
dataset_util.int64_feature(...),
'image/filename':
dataset_util.bytes_feature(...),
'image/source_id':
dataset_util.bytes_feature(...),
'image/key/sha256':
dataset_util.bytes_feature(...),
'image/encoded':
dataset_util.bytes_feature(...),
'image/format':
dataset_util.bytes_feature(...),
'image/object/bbox/xmin':
dataset_util.float_list_feature(...),
'image/object/bbox/xmax':
dataset_util.float_list_feature(...),
'image/object/bbox/ymin':
dataset_util.float_list_feature(...),
'image/object/bbox/ymax':
dataset_util.float_list_feature(...),
'image/object/class/text':
dataset_util.bytes_list_feature(....),
'image/object/is_crowd':
dataset_util.int64_list_feature(...),
'image/object/area':
dataset_util.float_list_feature(...),
}
Just need to make sure the feature_dict filed corresponds to the correct field from the annotations_list and the label_map.
You may wonder why exactly these fields in the feature_dict is necessary, according to the official documentation using your own dataset, the following fileds are necessary and others are optional.
'image/height': dataset_util.int64_feature(height),
'image/width': dataset_util.int64_feature(width),
'image/filename': dataset_util.bytes_feature(filename),
'image/source_id': dataset_util.bytes_feature(filename),
'image/encoded': dataset_util.bytes_feature(encoded_image_data),
'image/format': dataset_util.bytes_feature(image_format),
'image/object/bbox/xmin': dataset_util.float_list_feature(xmins),
'image/object/bbox/xmax': dataset_util.float_list_feature(xmaxs),
'image/object/bbox/ymin': dataset_util.float_list_feature(ymins),
'image/object/bbox/ymax': dataset_util.float_list_feature(ymaxs),
'image/object/class/text': dataset_util.bytes_list_feature(classes_text),
'image/object/class/label': dataset_util.int64_list_feature(classes),
Related
I have a problem to save my data from a radar device to a mat.file. Why do I wanna use a mat.file? Cause i want to use a SAR-algorithm afterwards in matlab. The radar what i am using is the 2 PI Labs SENSE X1155S-E radar. Additionally i am pretty new to python, that means my knowledge comes from forums and the documentation of python. I spent days testing things like "scipy.io.savemat", "pickle.dump", "file.write/.read" or "self.write", but I still can not save my data as i need it.
Here is an extract of my code:
# Dump a configuration object with all configured settings
config = device.sense.dump()
logger.info(f'Configuration: {config}')
logger.info('+ Running sweep(s)')
acq = device.initiate.immediate_and_receive()
# Read all data in one go
logger.info(' Read data')
data = acq.read()
# print(type(data)) # datatype check
logger.info(' Save data')
# create dict for storage
exportDict = {'data': data}
io.savemat("test.mat", exportDict)
With the commandline "data = acq.read()" i get the data from my radar. Now i want to use io.savemat() to save my data in a mat.file, but for some reason I always get an error:
"TypeError: Could not convert None (type <class 'NoneType'>) to array"
I could not fix it until today. Maybe someone can help me to understand, what i am doing wrong. If you need some more information, I can poste more for sure.
Here are 2 pictures of my data and the error. Hope it helps. Thanks.
screenshot of my variable "data" ;
screenshot of my error
Finally i managed to solve my problem.
As u can see in my first picture "variable data" there is a subpoint called "array", so i edit my code as follow:
import numpy as np
import scipy.io as
logger.info(' Save data')
# create dict for storage
exportDict = {'data': data.array}
io.savemat("test.mat", exportDict)
Now i can save the right data as i need it.
I'm new to Drake.And I want to use my robot model which is a ROS urdf package converted from SolidWorks plugin.I've tried to use
builder = DiagramBuilder()
plant, scene_graph = AddMultibodySceneGraph(builder,0.0)
parser = Parser(plant)
pkg_map = parser.package_map()
pkg_map.AddPackageXml("myxmlfilepath")
robot_file = "my_urdf_file_path"
robot = parser.AddModelFromFile(robot_file, "robot")
But I got an errorRuntimeError:The WaveFront obj file has no faces in the last line.I try to use ROS to display and it works well. My urdf file has some .stl format mesh file for visual and collision. I see some comments here, so I guess Drake maybe can't deal with .stl in a default way so far.What should I do except manually converting .stl mesh file to .obj file? Thanks in Advance.
As you noted in your comment above, once you converted your STL file to an OBJ file, you were able to load your URDF file.
This is because Drake does not yet support loading STL (or DAE) meshes at runtime; they must be converted (either manually as you had done, or via the build system). For more info, please see:
https://github.com/RobotLocomotion/drake/issues/2941
In that issue, I've referenced your post as a motivator towards adding additional mesh support.
Thanks!
I use OTB (Orfeo Tool Box) in QGis for classification. When I use the ImageTrainClassifier tool in a batch process, I have a problem for some images. Instead of returning a model in a xml/txt file format, it returns several files with those extensions : .xml_rates_1, .xml_samples_1.dbf, .xml_samples_1.prj, .xml_samples_1.shp, .xml_samples_1.shx, .xml_stats_1 (I have the same files with txt instead of xml if I use txt file format as output).
During the execution of the algorithms, I have only one warning message :
(WARNING): file ..\Modules\Learning\Sampling\src\otbSamplingRateCalculatorList.cxx, line 99, SamplingRateCalculatorList (00000283DDC3C0E0): All classes are empty !
And after that :
(FATAL) TrainImagesClassifier: No samples found in the inputs!
The problem is that after that, I want to use ImageClassifier, that takes the model of ImageTrainClassifier in input, that I don’t have.
Thanks for your help
I am new to image processing and have just started working in OpenCV. I was trying to do object detection using GenericDescriptorMatcher of type fern. But I don't know what to pass as the params_filename. What should be the format of the file? What parameters do I write in the file and in what format?
Ptr<GenericDescriptorMatcher> descriptorMatcher = GenericDescriptorMatcher::create("FERN", params_filename);
The opencv-2.x.x/samples/cpp should contain an example version of 'fern_params.xml', which according to opencv-2.4.8 contains the following xml content,
<?xml version="1.0"?>
<opencv_storage>
<nclasses>0</nclasses>
<patchSize>31</patchSize>
<signatureSize>INT_MAX</signatureSize>
<nstructs>50</nstructs>
<structSize>9</structSize>
<nviews>1000</nviews>
<compressionMethod>0</compressionMethod>
</opencv_storage>
I am trying to create individuals and save them in OWL file. The OWL file was created in Protégé. The size of the file was 10KB but after trying to save the individuals in the ontology the size of the code becomes 7KB.
Then I tried to open the OWL file using Protégé but it will not open.
The code is:
String SOURCE = "http://www.semanticweb.org/ontologies/2012/9/untitled-ontology-19";
String NS = SOURCE + "#";
OntModel onto = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
onto.read("file:/home/tourism.owl", "RDF/XML");
OntClass place = onto.getOntClass(NS+"Mountains");
Individual am1 = onto.createIndividual(NS+Concept1, place);
FileOutputStream output = null;
try {
output = new FileOutputStream( "/home/tourism.owl ");
} catch(Exception e) {}
onto.writeAll(output, "RDF/XML-ABBREV","xmlbase");
Have you checked that the new file does not contain the new information? It may have been written out in a more compact form that than the original file because you used the "RDF/XML-ABBREV" form.
PS "xmlbase" should be a URI.
Jena is purely RDF/XML based API for accessing Ontology or Models. Make a Note of these things: What is the format when you save your OWL file after editing it with Protege? Is it OWL/XML or RDF/XML?? Jena being RDF centric can read OWL files written in RDF/XML format, but cannot read OWL file written in OWL/XML syntax (specifically the OWL2 syntax). Similarly it can write a Model/OntModel from memory to OWL file or an RDF file but ALWAYS in either "RDF/XML" syntax or "N3" or "RDF/XML-ABBREV".
And Since you are using "RDF/XML-ABBREV", which lists your triples in abbreviated format.. possibly that is the reason why your output file is decreasing in size.