models icon indicating copy to clipboard operation
models copied to clipboard

Unable to generate TFRrecord: getting error : TypeError: None has type NoneType, but expected one of: int, long :

Open venkateshbabusekar opened this issue 8 years ago • 13 comments

(tensorflow2) C:\tensorflow2\models\research\object_detection>python generate_tfrecord.py --csv_input=images\train_labels.csv --image_dir=images\train --output_path=train.record Traceback (most recent call last): File "generate_tfrecord.py", line 100, in tf.app.run() File "C:\Users\babus\Anaconda3\envs\tensorflow2\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run _sys.exit(main(argv)) File "generate_tfrecord.py", line 91, in main tf_example = create_tf_example(group, path) File "generate_tfrecord.py", line 80, in create_tf_example 'image/object/class/label': dataset_util.int64_list_feature(classes), File "C:\Users\babus\Anaconda3\envs\tensorflow2\lib\site-packages\object_detection-0.1-py3.5.egg\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

venkateshbabusekar avatar Oct 01 '18 12:10 venkateshbabusekar

found the solution

If you're getting error "TypeError: None has type NoneType, but expected one of: int, long" .

To fix, go to generate_tfrecord.py and under def class_text_to_int, the last else statement should be a return 0, not None. This makes sense, since we are expecting an int but are getting back a none.

venkateshbabusekar avatar Oct 01 '18 12:10 venkateshbabusekar

Closing as this is resolved

wt-huang avatar Nov 17 '18 20:11 wt-huang

found the solution

If you're getting error "TypeError: None has type NoneType, but expected one of: int, long" .

To fix, go to generate_tfrecord.py and under def class_text_to_int, the last else statement should be a return 0, not None. This makes sense, since we are expecting an int but are getting back a none.

I tried this, I still got the same error.

Yazmaz98 avatar Nov 17 '19 20:11 Yazmaz98

found the solution If you're getting error "TypeError: None has type NoneType, but expected one of: int, long" . To fix, go to generate_tfrecord.py and under def class_text_to_int, the last else statement should be a return 0, not None. This makes sense, since we are expecting an int but are getting back a none.

I tried this, I still got the same error.

You should not get it, check it once again. If you are still getting the same error, then share the code here someone will help you.

amitjslearn avatar Jan 08 '20 19:01 amitjslearn

found the solution

If you're getting error "TypeError: None has type NoneType, but expected one of: int, long" .

To fix, go to generate_tfrecord.py and under def class_text_to_int, the last else statement should be a return 0, not None. This makes sense, since we are expecting an int but are getting back a none.

This solution solves this issue for me too.... Just change the 'None' to return 0. and that's all

tijazz avatar Jan 22 '20 07:01 tijazz

Yes this solution works. Just change your label to desired label name.

Working Function:

def class_text_to_int(row_label):
    if row_label == 'racoon':
        return 1
    else:
        return 0

ankitom avatar Mar 11 '20 08:03 ankitom

解决了,return None 改成 return 0,但是之前return None一直是没问题的,不知道有时候就会出错。。

swzaaaaaaa avatar Apr 08 '20 02:04 swzaaaaaaa

found the solution

If you're getting error "TypeError: None has type NoneType, but expected one of: int, long" .

To fix, go to generate_tfrecord.py and under def class_text_to_int, the last else statement should be a return 0, not None. This makes sense, since we are expecting an int but are getting back a none.

Awesome Thank very much

ttaahhaa avatar Aug 20 '20 07:08 ttaahhaa

found the solution

If you're getting error "TypeError: None has type NoneType, but expected one of: int, long" .

To fix, go to generate_tfrecord.py and under def class_text_to_int, the last else statement should be a return 0, not None. This makes sense, since we are expecting an int but are getting back a none.

thanks, you're right. I fix this issue as soon as I change 'None' to '0'.

TomatoQt avatar Sep 19 '20 08:09 TomatoQt

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'.

shubhamnagalwade avatar Mar 06 '21 10:03 shubhamnagalwade

To solve typeerror on genrate TFrecord file: def class_text_to_int(row_label): if row_label == 'x': return 1 elif row_label == 'y': return 2 elif row_label == 'Z': return 3 else: return None Solution: else: return 0

sonkarsr avatar Jul 09 '21 06:07 sonkarsr

I got this error but what resolved it for me was making sure the labels matched what I needed. This means I had 14 objects I was trying to detect, but I had only 4 in my def class_text_to_int. After adding the other 10 object it worked as intended.

If you only change the else to return 0, then you will probably will not get the correct output.

Something that could help is adding a print in def class_text_to_int(row_label): if row_label == 'name': return 1 else: print(row_label) None

This way you will learn which label is not being read properly and can add a new int for this new class.

DylanFendrich avatar Aug 13 '21 01:08 DylanFendrich

Yes this solution works. Just change your label to desired label name.

Working Function:

def class_text_to_int(row_label):
    if row_label == 'racoon':
        return 1
    else:
        return 0

this helps a lot. I am using tensorflow 2.6 version, I had compatible issue. Then use this to update the generate TFRecord py file, it works. Thanks

chendbox avatar Sep 23 '21 23:09 chendbox