Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: None has type NoneType, but expected one of: int, long #2

Closed
jtara1 opened this issue Aug 1, 2017 · 19 comments
Closed

TypeError: None has type NoneType, but expected one of: int, long #2

jtara1 opened this issue Aug 1, 2017 · 19 comments

Comments

@jtara1
Copy link

jtara1 commented Aug 1, 2017

I have 23 images I'm testing this out with. I labeled my images with the bounding boxes using labelimg. I cloned this repo and updated the contents of the images, annotations, data, and training folders to hold the data I'm using. I ran the xml_to_csv.py script.
I ran the generate_tfrecord.py script and got this error.

j@j-pc ~/_Github-Projects/raccoon-dataset $ python3 generate_tfrecord.py --csv_input=./data/raccoon_labels.csv --output_path=train.record
Traceback (most recent call last):
  File "generate_tfrecord.py", line 76, in <module>
    tf.app.run()
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "generate_tfrecord.py", line 69, in main
    tf_example = create_tf_example(row)
  File "generate_tfrecord.py", line 60, in create_tf_example
    'image/object/class/label': dataset_util.int64_list_feature(classes),
  File "/home/j/Lib/models/object_detection/utils/dataset_util.py", line 26, in int64_list_feature
    return tf.train.Feature(int64_list=tf.train.Int64List(value=value))
TypeError: None has type NoneType, but expected one of: int, long
@jtara1
Copy link
Author

jtara1 commented Aug 1, 2017

Changing the string in https://github.com/datitran/raccoon-dataset/blob/master/generate_tfrecord.py#L25 to the label I'm using ('iron ore') for my data seems to have fixed this. No errors now and I got the train.record file. I'll probably close this issue later after I make sure this file is legit.

@jtara1 jtara1 closed this as completed Aug 5, 2017
@Zumbalamambo
Copy link

@jtara1 what do you mean by iron ore?

@jtara1
Copy link
Author

jtara1 commented Aug 31, 2017

'iron ore' is the label I assigned. It describes what I'm training the model to detect, that is, iron ore, an object from an online game.

Whatever your label is, it should match what's located in https://github.com/datitran/raccoon_dataset/blob/master/training/object-detection.pbtxt

(raw text):

item {
  id: 1
  name: 'raccoon'
}

my previous comment points to the wrong line number; at that time I needed to replace the string 'raccoon' in the func below of the same file with 'iron ore' b/c that was my label

# TO-DO replace this with label map
def class_text_to_int(row_label):
    if row_label == 'raccoon':
        return 1
    else:
        None

It's been a while since I touched this stuff, mb if I misstated something.

@shauviks
Copy link

Can some one help me on this. Even i changed return value to 0 but i still get the same error

@prameshbajra
Copy link

@shauviks can you post your error trace? or did you solve it?

@Iamhomkar
Copy link

My Stack Trace before making the change
Traceback (most recent call last):
File "generate_tfrecord.py", line 107, in
tf.app.run()
File "/home/shadeslayer/anaconda/envs/MYML/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "generate_tfrecord.py", line 98, in main
tf_example = create_tf_example(group, path)
File "generate_tfrecord.py", line 87, in create_tf_example
'image/object/class/label': dataset_util.int64_list_feature(classes),
File "/home/shadeslayer/Documents/Tensorflow_Object_detection/models/research/object_detection/utils/dataset_util.py", line 26, in int64_list_feature
return tf.train.Feature(int64_list=tf.train.Int64List(value=value))
TypeError: None has type NoneType, but expected one of: int, long

TO-DO replace this with label map

def class_text_to_int(row_label):
if row_label == 'raccoon':
return 1
else:
None

This should return an integer in the else case,since line number 87 "'image/object/class/label': dataset_util.int64_list_feature(classes)," expects it to be an integer, returning an integer like 0 worked for me.

@pranavjadhav001
Copy link

This happens because labels in your xml are wrong in someplaces, check your csv and change those mistakes. Like instead of racoon label , you have labelled it as car.

@jayasuryar97
Copy link

My object-detection.pbtxt
item { id: 1 name: 'PAN' } item { id: 2 name: 'Cheque' } item { id: 3 name: 'Unknown' }
It has multiple classes.
How do i modify my class_text_to_int function for multi class

@nuttheguitar
Copy link

python generate_tfrecord.py --label=person --csv_input=../../annotations/train_labels.csv --output_path=../../annotations/train_labels.record --img_path=../../images/train

This is my run script. I just change '--label' to match with a class that you assigned in label_map.txt

@adarsh666
Copy link

This usually happens when "label name" specified to create the tf record mismatches with the "label name" in the annotation files.
For example if u annotated an image by the name "cars" , and u incorrectly named label as "car" while creating tf record.

@SirPhemmiey
Copy link

SirPhemmiey commented Jan 7, 2020

The solution is a simple one.

You just need to change the else statement so it returns 0 instead of "None".

def class_text_to_int(row_label): if row_label == '<YOUR LABEL NAME>': return 1 else: return 0

You can find def class_text_to_int in the generate_tfrecord.py file.

Most forums talk about return equal None. It should be zero.

Ref: here

I hope it works for you!

@Daring-Deekshith
Copy link

The solution is a simple one.

You just need to change the else statement so it returns 0 instead of "None".

def class_text_to_int(row_label): if row_label == '<YOUR LABEL NAME>': return 1 else: return 0

You can find def class_text_to_int in the generate_tfrecord.py file.

Most forums talk about return equal None. It should be zero.

Ref: here

I hope it works for you!

It is working great.
Thank you.
Simply do the thing in the image.
solved_return

@yashmukaty
Copy link

The solution is a simple one.

You just need to change the else statement so it returns 0 instead of "None".

def class_text_to_int(row_label): if row_label == '<YOUR LABEL NAME>': return 1 else: return 0

You can find def class_text_to_int in the generate_tfrecord.py file.

Most forums talk about return equal None. It should be zero.

Ref: here

I hope it works for you!

It still doesn't work!

@IndiskPrasad
Copy link

@yashmukaty , it worked for me by simply adding 0 instead of None. thanks

@bahshat
Copy link

bahshat commented May 15, 2020

You need this piece

def class_text_to_int(row_label):
    if row_label == '<YOUR LABEL NAME>': 
         return 1 
    else: 
         return 0

You can find def class_text_to_int in the generate_tfrecord.py file.
find the else shown in the above code
there you'd see

else: 
         None

make as above code which needs to be replaced with

  else: 
         return 0

@dhanpalrajpurohit
Copy link

if row_label == 'raccon': return 1 else: None
convert to
if row_label == 'raccon': return 1 else: return 0

@gilmotta
Copy link

gilmotta commented Oct 9, 2020

My Stack Trace before making the change
Traceback (most recent call last):
File "generate_tfrecord.py", line 107, in
tf.app.run()
File "/home/shadeslayer/anaconda/envs/MYML/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "generate_tfrecord.py", line 98, in main
tf_example = create_tf_example(group, path)
File "generate_tfrecord.py", line 87, in create_tf_example
'image/object/class/label': dataset_util.int64_list_feature(classes),
File "/home/shadeslayer/Documents/Tensorflow_Object_detection/models/research/object_detection/utils/dataset_util.py", line 26, in int64_list_feature
return tf.train.Feature(int64_list=tf.train.Int64List(value=value))
TypeError: None has type NoneType, but expected one of: int, long

TO-DO replace this with label map

def class_text_to_int(row_label):
if row_label == 'raccoon':
return 1
else:
None

This should return an integer in the else case,since line number 87 "'image/object/class/label': dataset_util.int64_list_feature(classes)," expects it to be an integer, returning an integer like 0 worked for me.

This function only makes sense if you want to filter your label in csv with many labels but the code isn't checking for None so it doesn't have purpose.
Just comment out the whole thing and return 1 always

Below is what I did and it works for all labels I have in my csv:

TO-DO replace this with label map

def class_text_to_int(row_label):
# print(row_label + " ")
# if row_label == 'car' or row_label == 'plate'
# or row_label == 'motorcycle' or row_label == 'bus'
# or row_label == 'volkwagen' or row_label == 'chevrolet'
# or row_label == 'truck' or row_label == 'van' or row_label == 'suv':
# return 1
# else:
# None
return 1

@mahmudsaral
Copy link

The solution is a simple one.

You just need to change the else statement so it returns 0 instead of "None".

def class_text_to_int(row_label): if row_label == '<YOUR LABEL NAME>': return 1 else: return 0

You can find def class_text_to_int in the generate_tfrecord.py file.

Most forums talk about return equal None. It should be zero.

Ref: here

I hope it works for you!

Thanks for the help :)

@shubhamnagalwade
Copy link

Just change the label name whatever you labeling them during crop the image by labelImg tool.

def class_text_to_int(row_label):
    if row_label == 'raccon':
        return 1
    else:
        None

Instead of 'raccon' put label name for ex:- 'car'.

NOTE:- for windows just change the forward-slash like:-
python3 generate_tfrecord.py --csv_input=data\test_labels.csv --output_path=data\test.record

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests