tensorflow / hub

A library for transfer learning by reusing parts of TensorFlow models.
https://tensorflow.org/hub
Apache License 2.0
3.48k stars 1.66k forks source link

"ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format." When trying to train custom object detector #841

Closed FlyWong closed 2 years ago

FlyWong commented 2 years ago

Hi,

I am trying to train a custom object detector using this guide as a reference: https://medium.com/@poulinakis.kon/object-detection-at-the-edge-with-tf-lite-model-maker-e635a17b0854

I was able to import object_detector from tflite_model_maker:

from tflite_model_maker import object_detector

However, when I tried to training the model by running:

model = object_detector.ObjectDetector.create(train_data=train_ds, #train dataset ... model_spec=spec, #model specification ... epochs=100, #training epochs ... validation_data = val_ds, #validation subset ... batch_size= 4, ... train_whole_model=False, ... do_train = True ... )

However, I got the following error:

File "c:\Users\dev\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_examples\lite\model_maker\third_party\efficientdet\keras\train_lib.py", line 885, in call cls_outputs, box_outputs = self.base_model(inputs, training=training) File "c:\Users\dev\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\utils\traceback_utils.py", line 67, in error_handler raise e.with_traceback(filtered_tb) from None File "c:\Users\dev\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\autograph\impl\api.py", line 699, in wrapper raise e.ag_error_metadata.to_exception(e) ValueError: Exception encountered when calling layer "keras_layer_1" (type KerasLayer).

in user code:

File "c:\Users\dev\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_hub\keras_layer.py", line 213, in call  *
    self._check_trainability()
File "c:\Users\dev\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_hub\keras_layer.py", line 272, in _check_trainability  *
    raise ValueError(

ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format.

Call arguments received: • inputs=tf.Tensor(shape=(None, 320, 320, 3), dtype=float32) • training=False

(more details in file attached ErrorTrainingTFlite.txt) ErrorTrainingTFlite.txt

My environment is: Windows 10 Anconda3 (64) bits Python 3.8.6

tflite-model-maker, 0.3.4 keras, 2.7.0 tensorflow, 2.7.1 numpy, 1.22.2 tf-estimator-nightly, 2.8.0.dev2021122109 tflite-support, 0.3.1 tensorflow-addons, 0.15.0 tensorflow-datasets, 4.5.2 tf-models-official, 2.3.0 tensorflow-hub, 0.12.0 tensorflow-model-optimization, 0.6.0

Do let me know what else do you need to help with the troubleshooting.

akhorlin commented 2 years ago

This is a known limitation in the TF1/TF2 compatibility logic. hub.KerasLayer.trainable = True doesn't work for TF1 Hub modules. Unfortunately at this time, there are no plans to address this gap.

FlyWong commented 2 years ago

Hi,

I do not need TF1/TF2 compatibility. How can I configure so that the tflite model maker only runs for either TF1 or TF2?

Or can I downgrade the version of tflite model maker, tensorflow etc so that it only runs for TF1 or TF2?

Thanks, Raymond


From: Andrey Khorlin @.> Sent: Monday, February 14, 2022 6:00 PM To: tensorflow/hub @.> Cc: FlyWong @.>; Author @.> Subject: Re: [tensorflow/hub] "ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format." When trying to train custom object detector (Issue #841)

This is a known limitation in the TF1/TF2 compatibility logic. hub.KerasLayer.trainable = True doesn't work for TF1 Hub modules. Unfortunately at this time, there are no plans to address this gap.

— Reply to this email directly, view it on GitHubhttps://github.com/tensorflow/hub/issues/841#issuecomment-1038885013, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACPS7US3TAIHSR4RSGGXUS3U3DHD5ANCNFSM5OKKNCTA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.***>

akhorlin commented 2 years ago

Which http://thfub.dev model are you trying to load? The error indicates that the model in question is in the old TF1 format. hub.KerasLayer is the API designed to work with models stored in TF2 format. The old TF1 API is hub.Module(). For backwards compatibility, hub.KerasLayer can load TF1 models but only w/o fine-tuning (e.g. trainable = False).

https://medium.com/@poulinakis.kon/object-detection-at-the-edge-with-tf-lite-model-maker-e635a17b0854 seems to be a bit vague on which version of TF was used. Could it be that they used TF 1.x or ran TF2 in TF1 compat mode?

FlyWong commented 2 years ago

HI, I am trying to load efficientNet.

Is there any setting to make model maker only run for tf2. I do not need tf1.

Am quite new to custom model training so just following the step. The step dun seem to gave any setting to indicate tf1 or tf2.

Is there a better way to do train the custom model using tflite model maker?

Thanks

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Andrey Khorlin @.> Sent: Monday, February 14, 2022 6:21:07 PM To: tensorflow/hub @.> Cc: FlyWong @.>; Author @.> Subject: Re: [tensorflow/hub] "ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format." When trying to train custom object detector (Issue #841)

Which http://thfub.dev model are you trying to load? The error indicates that the model in question is in the old TF1 format. hub.KerasLayer is the API designed to work with models stored in TF2 format. The old TF1 API is hub.Module(). For backwards compatibility, hub.KerasLayer can load TF1 models but only w/o fine-tuning (e.g. trainable = False).

@.***/object-detection-at-the-edge-with-tf-lite-model-maker-e635a17b0854 seems to be a bit vague on which version of TF was used. Could it be that they used TF 1.x or ran TF2 in TF1 compat mode?

— Reply to this email directly, view it on GitHubhttps://github.com/tensorflow/hub/issues/841#issuecomment-1038908095, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACPS7UUCDYLXUMH6O3UYIPDU3DJRHANCNFSM5OKKNCTA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.***>

FlyWong commented 2 years ago

Hi,

I tried to run the example from tensorflow tutorial

https://www.tensorflow.org/lite/tutorials/model_maker_object_detection

[https://www.tensorflow.org/site-assets/images/project-logos/tensorflow-lite-logo-social.png]https://www.tensorflow.org/lite/tutorials/model_maker_object_detection Object Detection with TensorFlow Lite Model Makerhttps://www.tensorflow.org/lite/tutorials/model_maker_object_detection In this colab notebook, you'll learn how to use the TensorFlow Lite Model Maker library to train a custom object detection model capable of detecting salads within images on a mobile device.. The Model Maker library uses transfer learning to simplify the process of training a TensorFlow Lite model using a custom dataset. Retraining a TensorFlow Lite model with your own custom dataset reduces ... www.tensorflow.org but with my own dataset. I ran into the same error too.

model = object_detector.create(train_data=train_ds, model_spec=spec, batch_size=8, train_whole_model=True, validation_data=val_ds) Traceback (most recent call last): File "", line 1, in File "c:\Users\raywl\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_examples\lite\model_maker\core\task\object_detector.py", line 260, in create object_detector.train(train_data, validation_data, epochs, batch_size) File "c:\Users\raywl\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_examples\lite\model_maker\core\task\object_detector.py", line 123, in train return self.model_spec.train(self.model, train_ds, steps_per_epoch, File "c:\Users\raywl\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_examples\lite\model_maker\core\task\model_spec\object_detector_spec.py", line 264, in train train.setup_model(model, config) File "c:\Users\raywl\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_examples\lite\model_maker\third_party\efficientdet\keras\train.py", line 113, in setup_model model.build((None, *config.image_size, 3)) File "c:\Users\raywl\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\engine\training.py", line 440, in build self.call(x, **kwargs) File "c:\Users\raywl\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_examples\lite\model_maker\third_party\efficientdet\keras\train_lib.py", line 885, in call cls_outputs, box_outputs = self.base_model(inputs, training=training) File "c:\Users\raywl\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\utils\traceback_utils.py", line 67, in error_handler raise e.with_traceback(filtered_tb) from None File "c:\Users\raywl\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\autograph\impl\api.py", line 699, in wrapper raise e.ag_error_metadata.to_exception(e) ValueError: Exception encountered when calling layer "keras_layer" (type KerasLayer).

in user code:

File "c:\Users\raywl\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_hub\keras_layer.py", line 213, in call  *
    self._check_trainability()
File "c:\Users\raywl\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_hub\keras_layer.py", line 272, in _check_trainability  *
    raise ValueError(

ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format.

Call arguments received: • inputs=tf.Tensor(shape=(None, 320, 320, 3), dtype=float32) • training=False

exit()

How can I configure tflite-model-maker to run only for TF2? Other is there other ways to run the model maker?

Thanks Raymond


From: raymond wong @.> Sent: Monday, February 14, 2022 7:23 PM To: tensorflow/hub @.>; tensorflow/hub @.> Cc: Author @.> Subject: Re: [tensorflow/hub] "ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format." When trying to train custom object detector (Issue #841)

HI, I am trying to load efficientNet.

Is there any setting to make model maker only run for tf2. I do not need tf1.

Am quite new to custom model training so just following the step. The step dun seem to gave any setting to indicate tf1 or tf2.

Is there a better way to do train the custom model using tflite model maker?

Thanks

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Andrey Khorlin @.> Sent: Monday, February 14, 2022 6:21:07 PM To: tensorflow/hub @.> Cc: FlyWong @.>; Author @.> Subject: Re: [tensorflow/hub] "ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format." When trying to train custom object detector (Issue #841)

Which http://thfub.dev model are you trying to load? The error indicates that the model in question is in the old TF1 format. hub.KerasLayer is the API designed to work with models stored in TF2 format. The old TF1 API is hub.Module(). For backwards compatibility, hub.KerasLayer can load TF1 models but only w/o fine-tuning (e.g. trainable = False).

@.***/object-detection-at-the-edge-with-tf-lite-model-maker-e635a17b0854 seems to be a bit vague on which version of TF was used. Could it be that they used TF 1.x or ran TF2 in TF1 compat mode?

— Reply to this email directly, view it on GitHubhttps://github.com/tensorflow/hub/issues/841#issuecomment-1038908095, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACPS7UUCDYLXUMH6O3UYIPDU3DJRHANCNFSM5OKKNCTA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.***>

ziyeqinghan commented 2 years ago

May I ask if you change model_spec? Otherwise, seems that this shouldn't happen since we use tf2 hub module https://tfhub.dev/tensorflow/efficientdet/lite0/feature-vector/1

FlyWong commented 2 years ago

Hi,

I did not specifically modify the the model_spec. Below is my full training codes:

import numpy as np import os from tflite_model_maker.config import ExportFormat from tflite_model_maker import model_spec from tflite_model_maker import object_detector import tensorflow as tf assert tf.version.startswith('2')

tr_image_dir='C:\Users\dev\workspace\training_demo\train'

val_image_dir='C:\Users\dev\workspace\training_demo\test' label_map={1:'hRacket'}

/ for new project, make sure cache directory is clean / c_dir = 'C:\Users\dev\workspace\cache'

train_ds = object_detector.DataLoader.from_pascal_voc(images_dir=tr_image_dir, annotations_dir= tr_image_dir, label_map=label_map, cache_dir=c_dir) val_ds = object_detector.DataLoader.from_pascal_voc(images_dir=val_image_dir, annotations_dir= val_image_dir, label_map=label_map, cache_dir=c_dir) print("Train dataset contains {} images".format(train_ds.len())) print("Validation dataset contains {} images".format(val_ds.len()))

spec = model_spec.get("efficientdet_lite0")

model = object_detector.ObjectDetector.create(train_data=train_ds, #train dataset model_spec=spec, #model specification epochs=100, #training epochs validation_data = val_ds, #validation subset batch_size= 4, train_whole_model=False, do_train = True ) model.export(export_dir= 'C:\Users\dev\workspace\tflite', tflite_filename= 'racket.tflite' )

Is there anyway I can output the model_spec to check?

Thanks


From: Yuqi Li @.> Sent: Tuesday, February 15, 2022 3:21 PM To: tensorflow/hub @.> Cc: FlyWong @.>; Author @.> Subject: Re: [tensorflow/hub] "ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format." When trying to train custom object detector (Issue #841)

May I ask if you change model_spec? Otherwise, seems that is shouldn't happened since we use tf2 hub module https://tfhub.dev/tensorflow/efficientdet/lite0/feature-vector/1

— Reply to this email directly, view it on GitHubhttps://github.com/tensorflow/hub/issues/841#issuecomment-1039936946, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACPS7UU3BCQKDHOPKYDLHQDU3H5G7ANCNFSM5OKKNCTA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.***>

WGierke commented 2 years ago

Unfortunately, I cannot reproduce the issue on Colab:

!pip install -U tensorflow==2.7.1
!pip install -U tflite-model-maker==0.3.4
!pip install -U keras==2.7.0
!pip install -U numpy==1.22.2
!pip install -U tf-estimator-nightly==2.8.0.dev2021122109
!pip install -U tflite-support==0.3.1
!pip install -U tensorflow-addons==0.15.0
!pip install -U tensorflow-datasets==4.5.2
!pip install -U tf-models-official==2.3.0
!pip install -U tensorflow-hub==0.12.0
!pip install -U tensorflow-model-optimization==0.6.0
!pip freeze

import numpy as np
import os

from tflite_model_maker.config import QuantizationConfig
from tflite_model_maker.config import ExportFormat
from tflite_model_maker import model_spec
from tflite_model_maker import object_detector

import tensorflow as tf
assert tf.__version__.startswith('2')

tf.get_logger().setLevel('ERROR')
from absl import logging
logging.set_verbosity(logging.ERROR)

spec = model_spec.get("efficientdet_lite0")
print(spec.__dict__)

train_data, validation_data, test_data = object_detector.DataLoader.from_csv('gs://cloud-ml-data/img/openimage/csv/salads_ml_use.csv')
model = object_detector.ObjectDetector.create(train_data=train_data, #train dataset
                                             model_spec=spec, #model specification
                                             epochs=100, #training epochs
                                             validation_data = validation_data, #validation subset
                                             batch_size= 4,
                                             train_whole_model=False,
                                             do_train = True
                                             )
# {'model_name': 'efficientdet-lite0', 'uri': 'https://tfhub.dev/tensorflow/efficientdet/lite0/feature-vector/1', 'batch_size': 64, 'ds_strategy': <tensorflow.python.distribute.one_device_strategy.OneDeviceStrategy object at 0x7f759601cf10>, 'config': {'name': 'efficientdet-lite0', 'act_type': 'relu6', 'image_size': (320, 320), 'target_size': None, 'input_rand_hflip': True, 'jitter_min': 0.1, 'jitter_max': 2.0, 'autoaugment_policy': None, 'grid_mask': False, 'sample_image': None, 'map_freq': 5, 'num_classes': 90, 'seg_num_classes': 3, 'heads': ['object_detection'], 'skip_crowd_during_training': True, 'label_map': None, 'max_instances_per_image': 100, 'regenerate_source_id': False, 'min_level': 3, 'max_level': 7, 'num_scales': 3, 'aspect_ratios': [1.0, 2.0, 0.5], 'anchor_scale': 3.0, 'is_training_bn': True, 'momentum': 0.9, 'optimizer': 'sgd', 'learning_rate': 0.08, 'lr_warmup_init': 0.008, 'lr_warmup_epoch': 1.0, 'first_lr_drop_epoch': 200.0, 'second_lr_drop_epoch': 250.0, 'poly_lr_power': 0.9, 'clip_gradients_norm': 10.0, 'num_epochs': 50, 'data_format': 'channels_last', 'mean_rgb': 127.0, 'stddev_rgb': 128.0, 'scale_range': False, 'label_smoothing': 0.0, 'alpha': 0.25, 'gamma': 1.5, 'delta': 0.1, 'box_loss_weight': 50.0, 'iou_loss_type': None, 'iou_loss_weight': 1.0, 'weight_decay': 4e-05, 'strategy': None, 'mixed_precision': False, 'loss_scale': None, 'model_optimizations': {}, 'box_class_repeats': 3, 'fpn_cell_repeats': 3, 'fpn_num_filters': 64, 'separable_conv': True, 'apply_bn_for_resampling': True, 'conv_after_downsample': False, 'conv_bn_act_pattern': False, 'drop_remainder': True, 'nms_configs': {'method': 'gaussian', 'iou_thresh': None, 'score_thresh': 0.0, 'sigma': None, 'pyfunc': False, 'max_nms_inputs': 0, 'max_output_size': 100}, 'tflite_max_detections': 25, 'fpn_name': None, 'fpn_weight_method': 'sum', 'fpn_config': None, 'batch_norm_trainable': True, 'survival_prob': None, 'img_summary_steps': None, 'lr_decay_method': 'cosine', 'moving_average_decay': 0, 'ckpt_var_scope': None, 'skip_mismatch': True, 'backbone_name': 'efficientnet-lite0', 'backbone_config': None, 'var_freeze_expr': '(efficientnet|fpn_cells|resample_p6)', 'use_keras_model': True, 'dataset_type': None, 'positives_momentum': None, 'grad_checkpoint': False, 'verbose': 0, 'save_freq': 'epoch', 'profile': False, 'model_name': 'efficientdet-lite0', 'steps_per_execution': 1, 'model_dir': '/tmp/tmpshichm_6', 'batch_size': 64, 'tf_random_seed': 111111, 'debug': False}}
# Epoch 1/100 ...
FlyWong commented 2 years ago

Hi Willi,

is your Python also 3.8.6 and running on Windows 10.

I am trying to match our environment


From: Willi Gierke @.> Sent: Tuesday, February 15, 2022 5:41 PM To: tensorflow/hub @.> Cc: FlyWong @.>; Author @.> Subject: Re: [tensorflow/hub] "ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format." When trying to train custom object detector (Issue #841)

Unfortunately, I cannot reproduce the issue on Colab:

!pip install -U tensorflow==2.7.1 !pip install -U tflite-model-maker==0.3.4 !pip install -U keras==2.7.0 !pip install -U numpy==1.22.2 !pip install -U tf-estimator-nightly==2.8.0.dev2021122109 !pip install -U tflite-support==0.3.1 !pip install -U tensorflow-addons==0.15.0 !pip install -U tensorflow-datasets==4.5.2 !pip install -U tf-models-official==2.3.0 !pip install -U tensorflow-hub==0.12.0 !pip install -U tensorflow-model-optimization==0.6.0 !pip freeze

import numpy as np import os

from tflite_model_maker.config import QuantizationConfig from tflite_model_maker.config import ExportFormat from tflite_model_maker import model_spec from tflite_model_maker import object_detector

import tensorflow as tf assert tf.version.startswith('2')

tf.get_logger().setLevel('ERROR') from absl import logging logging.set_verbosity(logging.ERROR)

spec = model_spec.get("efficientdet_lite0") print(spec.dict)

train_data, validation_data, test_data = object_detector.DataLoader.from_csv('gs://cloud-ml-data/img/openimage/csv/salads_ml_use.csv') model = object_detector.ObjectDetector.create(train_data=train_data, #train dataset model_spec=spec, #model specification epochs=100, #training epochs validation_data = validation_data, #validation subset batch_size= 4, train_whole_model=False, do_train = True )

{'model_name': 'efficientdet-lite0', 'uri': 'https://tfhub.dev/tensorflow/efficientdet/lite0/feature-vector/1', 'batch_size': 64, 'ds_strategy': <tensorflow.python.distribute.one_device_strategy.OneDeviceStrategy object at 0x7f759601cf10>, 'config': {'name': 'efficientdet-lite0', 'act_type': 'relu6', 'image_size': (320, 320), 'target_size': None, 'input_rand_hflip': True, 'jitter_min': 0.1, 'jitter_max': 2.0, 'autoaugment_policy': None, 'grid_mask': False, 'sample_image': None, 'map_freq': 5, 'num_classes': 90, 'seg_num_classes': 3, 'heads': ['object_detection'], 'skip_crowd_during_training': True, 'label_map': None, 'max_instances_per_image': 100, 'regenerate_source_id': False, 'min_level': 3, 'max_level': 7, 'num_scales': 3, 'aspect_ratios': [1.0, 2.0, 0.5], 'anchor_scale': 3.0, 'is_training_bn': True, 'momentum': 0.9, 'optimizer': 'sgd', 'learning_rate': 0.08, 'lr_warmup_init': 0.008, 'lr_warmup_epoch': 1.0, 'first_lr_drop_epoch': 200.0, 'second_lr_drop_epoch': 250.0, 'poly_lr_power': 0.9, 'clip_gradients_norm': 10.0, 'num_epochs': 50, 'data_format': 'channels_last', 'mean_rgb': 127.0, 'stddev_rgb': 128.0, 'scale_range': False, 'label_smoothing': 0.0, 'alpha': 0.25, 'gamma': 1.5, 'delta': 0.1, 'box_loss_weight': 50.0, 'iou_loss_type': None, 'iou_loss_weight': 1.0, 'weight_decay': 4e-05, 'strategy': None, 'mixed_precision': False, 'loss_scale': None, 'model_optimizations': {}, 'box_class_repeats': 3, 'fpn_cell_repeats': 3, 'fpn_num_filters': 64, 'separable_conv': True, 'apply_bn_for_resampling': True, 'conv_after_downsample': False, 'conv_bn_act_pattern': False, 'drop_remainder': True, 'nms_configs': {'method': 'gaussian', 'iou_thresh': None, 'score_thresh': 0.0, 'sigma': None, 'pyfunc': False, 'max_nms_inputs': 0, 'max_output_size': 100}, 'tflite_max_detections': 25, 'fpn_name': None, 'fpn_weight_method': 'sum', 'fpn_config': None, 'batch_norm_trainable': True, 'survival_prob': None, 'img_summary_steps': None, 'lr_decay_method': 'cosine', 'moving_average_decay': 0, 'ckpt_var_scope': None, 'skip_mismatch': True, 'backbone_name': 'efficientnet-lite0', 'backbone_config': None, 'var_freeze_expr': '(efficientnet|fpn_cells|resample_p6)', 'use_keras_model': True, 'dataset_type': None, 'positives_momentum': None, 'grad_checkpoint': False, 'verbose': 0, 'save_freq': 'epoch', 'profile': False, 'model_name': 'efficientdet-lite0', 'steps_per_execution': 1, 'model_dir': '/tmp/tmpshichm_6', 'batch_size': 64, 'tf_random_seed': 111111, 'debug': False}}

Epoch 1/100 ...

— Reply to this email directly, view it on GitHubhttps://github.com/tensorflow/hub/issues/841#issuecomment-1040059485, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACPS7URV4X55KIRLYDGXSRDU3INUJANCNFSM5OKKNCTA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.***>

FlyWong commented 2 years ago

Hi all,

I have done quite a bit of installation and uninstallation. Not sure if my environment is messed up.

How can I start clean again? Eg. Any command to remove all tensorflow components. Also any folders to manually clean up?

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: raymond wong @.> Sent: Tuesday, February 15, 2022 6:13:06 PM To: tensorflow/hub @.>; tensorflow/hub @.> Cc: Author @.> Subject: Re: [tensorflow/hub] "ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format." When trying to train custom object detector (Issue #841)

Hi Willi,

is your Python also 3.8.6 and running on Windows 10.

I am trying to match our environment


From: Willi Gierke @.> Sent: Tuesday, February 15, 2022 5:41 PM To: tensorflow/hub @.> Cc: FlyWong @.>; Author @.> Subject: Re: [tensorflow/hub] "ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format." When trying to train custom object detector (Issue #841)

Unfortunately, I cannot reproduce the issue on Colab:

!pip install -U tensorflow==2.7.1 !pip install -U tflite-model-maker==0.3.4 !pip install -U keras==2.7.0 !pip install -U numpy==1.22.2 !pip install -U tf-estimator-nightly==2.8.0.dev2021122109 !pip install -U tflite-support==0.3.1 !pip install -U tensorflow-addons==0.15.0 !pip install -U tensorflow-datasets==4.5.2 !pip install -U tf-models-official==2.3.0 !pip install -U tensorflow-hub==0.12.0 !pip install -U tensorflow-model-optimization==0.6.0 !pip freeze

import numpy as np import os

from tflite_model_maker.config import QuantizationConfig from tflite_model_maker.config import ExportFormat from tflite_model_maker import model_spec from tflite_model_maker import object_detector

import tensorflow as tf assert tf.version.startswith('2')

tf.get_logger().setLevel('ERROR') from absl import logging logging.set_verbosity(logging.ERROR)

spec = model_spec.get("efficientdet_lite0") print(spec.dict)

train_data, validation_data, test_data = object_detector.DataLoader.from_csv('gs://cloud-ml-data/img/openimage/csv/salads_ml_use.csv') model = object_detector.ObjectDetector.create(train_data=train_data, #train dataset model_spec=spec, #model specification epochs=100, #training epochs validation_data = validation_data, #validation subset batch_size= 4, train_whole_model=False, do_train = True )

{'model_name': 'efficientdet-lite0', 'uri': 'https://tfhub.dev/tensorflow/efficientdet/lite0/feature-vector/1', 'batch_size': 64, 'ds_strategy': <tensorflow.python.distribute.one_device_strategy.OneDeviceStrategy object at 0x7f759601cf10>, 'config': {'name': 'efficientdet-lite0', 'act_type': 'relu6', 'image_size': (320, 320), 'target_size': None, 'input_rand_hflip': True, 'jitter_min': 0.1, 'jitter_max': 2.0, 'autoaugment_policy': None, 'grid_mask': False, 'sample_image': None, 'map_freq': 5, 'num_classes': 90, 'seg_num_classes': 3, 'heads': ['object_detection'], 'skip_crowd_during_training': True, 'label_map': None, 'max_instances_per_image': 100, 'regenerate_source_id': False, 'min_level': 3, 'max_level': 7, 'num_scales': 3, 'aspect_ratios': [1.0, 2.0, 0.5], 'anchor_scale': 3.0, 'is_training_bn': True, 'momentum': 0.9, 'optimizer': 'sgd', 'learning_rate': 0.08, 'lr_warmup_init': 0.008, 'lr_warmup_epoch': 1.0, 'first_lr_drop_epoch': 200.0, 'second_lr_drop_epoch': 250.0, 'poly_lr_power': 0.9, 'clip_gradients_norm': 10.0, 'num_epochs': 50, 'data_format': 'channels_last', 'mean_rgb': 127.0, 'stddev_rgb': 128.0, 'scale_range': False, 'label_smoothing': 0.0, 'alpha': 0.25, 'gamma': 1.5, 'delta': 0.1, 'box_loss_weight': 50.0, 'iou_loss_type': None, 'iou_loss_weight': 1.0, 'weight_decay': 4e-05, 'strategy': None, 'mixed_precision': False, 'loss_scale': None, 'model_optimizations': {}, 'box_class_repeats': 3, 'fpn_cell_repeats': 3, 'fpn_num_filters': 64, 'separable_conv': True, 'apply_bn_for_resampling': True, 'conv_after_downsample': False, 'conv_bn_act_pattern': False, 'drop_remainder': True, 'nms_configs': {'method': 'gaussian', 'iou_thresh': None, 'score_thresh': 0.0, 'sigma': None, 'pyfunc': False, 'max_nms_inputs': 0, 'max_output_size': 100}, 'tflite_max_detections': 25, 'fpn_name': None, 'fpn_weight_method': 'sum', 'fpn_config': None, 'batch_norm_trainable': True, 'survival_prob': None, 'img_summary_steps': None, 'lr_decay_method': 'cosine', 'moving_average_decay': 0, 'ckpt_var_scope': None, 'skip_mismatch': True, 'backbone_name': 'efficientnet-lite0', 'backbone_config': None, 'var_freeze_expr': '(efficientnet|fpn_cells|resample_p6)', 'use_keras_model': True, 'dataset_type': None, 'positives_momentum': None, 'grad_checkpoint': False, 'verbose': 0, 'save_freq': 'epoch', 'profile': False, 'model_name': 'efficientdet-lite0', 'steps_per_execution': 1, 'model_dir': '/tmp/tmpshichm_6', 'batch_size': 64, 'tf_random_seed': 111111, 'debug': False}}

Epoch 1/100 ...

— Reply to this email directly, view it on GitHubhttps://github.com/tensorflow/hub/issues/841#issuecomment-1040059485, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACPS7URV4X55KIRLYDGXSRDU3INUJANCNFSM5OKKNCTA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.***>

FlyWong commented 2 years ago

Hi,

Just to provide a bit more background, I also ran this tutorial on the same machine( including Tensorflow installation)

https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html

Could it have caused conflict? If so, how can I reset and start clean again.

Thanks

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: raymond wong @.> Sent: Tuesday, February 15, 2022 6:42:47 PM To: tensorflow/hub @.>; tensorflow/hub @.> Cc: Author @.> Subject: Re: [tensorflow/hub] "ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format." When trying to train custom object detector (Issue #841)

Hi all,

I have done quite a bit of installation and uninstallation. Not sure if my environment is messed up.

How can I start clean again? Eg. Any command to remove all tensorflow components. Also any folders to manually clean up?

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: raymond wong @.> Sent: Tuesday, February 15, 2022 6:13:06 PM To: tensorflow/hub @.>; tensorflow/hub @.> Cc: Author @.> Subject: Re: [tensorflow/hub] "ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format." When trying to train custom object detector (Issue #841)

Hi Willi,

is your Python also 3.8.6 and running on Windows 10.

I am trying to match our environment


From: Willi Gierke @.> Sent: Tuesday, February 15, 2022 5:41 PM To: tensorflow/hub @.> Cc: FlyWong @.>; Author @.> Subject: Re: [tensorflow/hub] "ValueError: Setting hub.KerasLayer.trainable = True is unsupported when loading from the TF1 Hub format." When trying to train custom object detector (Issue #841)

Unfortunately, I cannot reproduce the issue on Colab:

!pip install -U tensorflow==2.7.1 !pip install -U tflite-model-maker==0.3.4 !pip install -U keras==2.7.0 !pip install -U numpy==1.22.2 !pip install -U tf-estimator-nightly==2.8.0.dev2021122109 !pip install -U tflite-support==0.3.1 !pip install -U tensorflow-addons==0.15.0 !pip install -U tensorflow-datasets==4.5.2 !pip install -U tf-models-official==2.3.0 !pip install -U tensorflow-hub==0.12.0 !pip install -U tensorflow-model-optimization==0.6.0 !pip freeze

import numpy as np import os

from tflite_model_maker.config import QuantizationConfig from tflite_model_maker.config import ExportFormat from tflite_model_maker import model_spec from tflite_model_maker import object_detector

import tensorflow as tf assert tf.version.startswith('2')

tf.get_logger().setLevel('ERROR') from absl import logging logging.set_verbosity(logging.ERROR)

spec = model_spec.get("efficientdet_lite0") print(spec.dict)

train_data, validation_data, test_data = object_detector.DataLoader.from_csv('gs://cloud-ml-data/img/openimage/csv/salads_ml_use.csv') model = object_detector.ObjectDetector.create(train_data=train_data, #train dataset model_spec=spec, #model specification epochs=100, #training epochs validation_data = validation_data, #validation subset batch_size= 4, train_whole_model=False, do_train = True )

{'model_name': 'efficientdet-lite0', 'uri': 'https://tfhub.dev/tensorflow/efficientdet/lite0/feature-vector/1', 'batch_size': 64, 'ds_strategy': <tensorflow.python.distribute.one_device_strategy.OneDeviceStrategy object at 0x7f759601cf10>, 'config': {'name': 'efficientdet-lite0', 'act_type': 'relu6', 'image_size': (320, 320), 'target_size': None, 'input_rand_hflip': True, 'jitter_min': 0.1, 'jitter_max': 2.0, 'autoaugment_policy': None, 'grid_mask': False, 'sample_image': None, 'map_freq': 5, 'num_classes': 90, 'seg_num_classes': 3, 'heads': ['object_detection'], 'skip_crowd_during_training': True, 'label_map': None, 'max_instances_per_image': 100, 'regenerate_source_id': False, 'min_level': 3, 'max_level': 7, 'num_scales': 3, 'aspect_ratios': [1.0, 2.0, 0.5], 'anchor_scale': 3.0, 'is_training_bn': True, 'momentum': 0.9, 'optimizer': 'sgd', 'learning_rate': 0.08, 'lr_warmup_init': 0.008, 'lr_warmup_epoch': 1.0, 'first_lr_drop_epoch': 200.0, 'second_lr_drop_epoch': 250.0, 'poly_lr_power': 0.9, 'clip_gradients_norm': 10.0, 'num_epochs': 50, 'data_format': 'channels_last', 'mean_rgb': 127.0, 'stddev_rgb': 128.0, 'scale_range': False, 'label_smoothing': 0.0, 'alpha': 0.25, 'gamma': 1.5, 'delta': 0.1, 'box_loss_weight': 50.0, 'iou_loss_type': None, 'iou_loss_weight': 1.0, 'weight_decay': 4e-05, 'strategy': None, 'mixed_precision': False, 'loss_scale': None, 'model_optimizations': {}, 'box_class_repeats': 3, 'fpn_cell_repeats': 3, 'fpn_num_filters': 64, 'separable_conv': True, 'apply_bn_for_resampling': True, 'conv_after_downsample': False, 'conv_bn_act_pattern': False, 'drop_remainder': True, 'nms_configs': {'method': 'gaussian', 'iou_thresh': None, 'score_thresh': 0.0, 'sigma': None, 'pyfunc': False, 'max_nms_inputs': 0, 'max_output_size': 100}, 'tflite_max_detections': 25, 'fpn_name': None, 'fpn_weight_method': 'sum', 'fpn_config': None, 'batch_norm_trainable': True, 'survival_prob': None, 'img_summary_steps': None, 'lr_decay_method': 'cosine', 'moving_average_decay': 0, 'ckpt_var_scope': None, 'skip_mismatch': True, 'backbone_name': 'efficientnet-lite0', 'backbone_config': None, 'var_freeze_expr': '(efficientnet|fpn_cells|resample_p6)', 'use_keras_model': True, 'dataset_type': None, 'positives_momentum': None, 'grad_checkpoint': False, 'verbose': 0, 'save_freq': 'epoch', 'profile': False, 'model_name': 'efficientdet-lite0', 'steps_per_execution': 1, 'model_dir': '/tmp/tmpshichm_6', 'batch_size': 64, 'tf_random_seed': 111111, 'debug': False}}

Epoch 1/100 ...

— Reply to this email directly, view it on GitHubhttps://github.com/tensorflow/hub/issues/841#issuecomment-1040059485, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACPS7URV4X55KIRLYDGXSRDU3INUJANCNFSM5OKKNCTA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.***>