How to make tflite lite mobilenetv3 training on gpu machine without error

I am trying to make tflite mobilev3 model training on keras and I had the below error:

File “main.py”, line 11, in compile_validate_model
model.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(metrics=[‘categorical_accuracy’,
TypeError: init() got an unexpected keyword argument ‘metrics’

Does anyone have experience on the issue or have an information on it?

If anyone could suggest an endtoend description for the aim it’d be great, as well.

Thank you in advance.

Hi @murkoc, you are getting this error because tf.keras.losses.SparseCategoricalCrossentropy does not have metrics argument. you have to compile your model by

model.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy( ), metrics="accuracy")

Thank You.

1 Like

Thank you very much I am going to try it.

Hello,

I have tried your suggestion and passed the error but I have below output:

C:\Files\mobilenetv3_train\mobilenet_v3_tflite-master>python main.py --data_dir train_data --arch mobilenet_v3_small
2023-02-23 13:45:17.488626: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library ‘cudart64_101.dll’; dlerror: cudart64_101.dll not found
2023-02-23 13:45:17.517477: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2023-02-23 13:45:21.140273: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2023-02-23 13:45:21.237264: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0000:02:00.0 name: NVIDIA RTX A5000 computeCapability: 8.6
coreClock: 1.695GHz coreCount: 64 deviceMemorySize: 23.99GiB deviceMemoryBandwidth: 715.34GiB/s
2023-02-23 13:45:21.282176: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 1 with properties:
pciBusID: 0000:01:00.0 name: Quadro RTX 4000 computeCapability: 7.5
coreClock: 1.545GHz coreCount: 36 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 387.49GiB/s
2023-02-23 13:45:21.324937: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library ‘cudart64_101.dll’; dlerror: cudart64_101.dll not found
2023-02-23 13:45:21.352468: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library ‘cublas64_10.dll’; dlerror: cublas64_10.dll not found
2023-02-23 13:45:21.386838: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2023-02-23 13:45:21.413788: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2023-02-23 13:45:21.430844: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library ‘cusolver64_10.dll’; dlerror: cusolver64_10.dll not found
2023-02-23 13:45:21.454916: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library ‘cusparse64_10.dll’; dlerror: cusparse64_10.dll not found
2023-02-23 13:45:21.495762: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2023-02-23 13:45:21.516714: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1598] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at Install TensorFlow with pip for how to download and setup the required libraries for your platform.
Skipping registering GPU devices…
2023-02-23 13:45:21.565289: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2023-02-23 13:45:21.607717: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x209febc4520 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2023-02-23 13:45:21.634670: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
2023-02-23 13:45:21.656370: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2023-02-23 13:45:21.673693: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]
Pretrained model specified - loading weights
Compiling model for validation
Validating model
WARNING:tensorflow:From C:\Files\mobilenetv3_train\mobilenet_v3_tflite-master\imagenet_input.py:151: map_and_batch (from tensorflow.python.data.experimental.ops.batching) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.data.Dataset.map(map_func, num_parallel_calls) followed by tf.data.Dataset.batch(batch_size, drop_remainder). Static tf.data optimizations will take care of using the fused implementation.
Min crop size is: 0.20
WARNING:tensorflow:From C:\Files\mobilenetv3_train\mobilenet_v3_tflite-master\tf_preprocessing.py:59: sample_distorted_bounding_box (from tensorflow.python.ops.image_ops_impl) is deprecated and will be removed in a future version.
Instructions for updating:
seed2 arg is deprecated.Use sample_distorted_bounding_box_v2 instead.
Traceback (most recent call last):
File “main.py”, line 83, in
compile_validate_model(model, args.data_dir, args.num_classes, args.batch_size, args.num_steps)
File “main.py”, line 30, in compile_validate_model
results = model.evaluate(imagenet_val.input_fn(), steps=validation_steps, verbose=verbose)
File “C:\ProgramData\Anaconda3\envs\mobilenetfromTF2\lib\site-packages\tensorflow\python\keras\engine\training.py”, line 66, in _method_wrapper
return method(self, *args, **kwargs)
File “C:\ProgramData\Anaconda3\envs\mobilenetfromTF2\lib\site-packages\tensorflow\python\keras\engine\training.py”, line 1081, in evaluate
tmp_logs = test_function(iterator)
File “C:\ProgramData\Anaconda3\envs\mobilenetfromTF2\lib\site-packages\tensorflow\python\eager\def_function.py”, line 580, in call
result = self._call(*args, **kwds)
File “C:\ProgramData\Anaconda3\envs\mobilenetfromTF2\lib\site-packages\tensorflow\python\eager\def_function.py”, line 644, in _call
return self._stateless_fn(*args, **kwds)
File “C:\ProgramData\Anaconda3\envs\mobilenetfromTF2\lib\site-packages\tensorflow\python\eager\function.py”, line 2420, in call
return graph_function._filtered_call(args, kwargs) # pylint: disable=protected-access
File “C:\ProgramData\Anaconda3\envs\mobilenetfromTF2\lib\site-packages\tensorflow\python\eager\function.py”, line 1665, in _filtered_call
self.captured_inputs)
File “C:\ProgramData\Anaconda3\envs\mobilenetfromTF2\lib\site-packages\tensorflow\python\eager\function.py”, line 1746, in _call_flat
ctx, args, cancellation_manager=cancellation_manager))
File “C:\ProgramData\Anaconda3\envs\mobilenetfromTF2\lib\site-packages\tensorflow\python\eager\function.py”, line 598, in call
ctx=ctx)
File “C:\ProgramData\Anaconda3\envs\mobilenetfromTF2\lib\site-packages\tensorflow\python\eager\execute.py”, line 60, in quick_execute
inputs, attrs, num_outputs)
tensorflow.python.framework.errors_impl.DataLossError: corrupted record at 0
[[node IteratorGetNext (defined at main.py:30) ]] [Op:__inference_test_function_6653]

Function call stack:
test_function

any comment?

Hi @murkoc, It seems like there is an issue with your data. If you compress the data, you should get the data by tf.data.TFRecordDataset( output_path, compression_type ).For example, if you use GZIP compression you should use raw_dataset = tf.data.TFRecordDataset( output_path, compression_type = 'GZIP' ). Thank You.

1 Like