How to fine tune resnet50 with float16 in Keras? - python

I'm trying to fine tune resnet50 in half precision mode without success. It seems there are parts of model which are not compatible with float16. Here is my code:
dtype='float16'
K.set_floatx(dtype)
K.set_epsilon(1e-4)
model = Sequential()
model.add(ResNet50(weights='imagenet', include_top=False, pooling='avg'))
and I get this error:
Traceback (most recent call last):
File "train_resnet.py", line 40, in <module>
model.add(ResNet50(weights='imagenet', include_top=False, pooling='avg'))
File "/usr/local/lib/python3.6/dist-packages/keras/applications/__init__.py", line 28, in wrapper
return base_fun(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/keras/applications/resnet50.py", line 11, in ResNet50
return resnet50.ResNet50(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/keras_applications/resnet50.py", line 231, in ResNet50
x = layers.BatchNormalization(axis=bn_axis, name='bn_conv1')(x)
File "/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py", line 457, in __call__
output = self.call(inputs, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/keras/layers/normalization.py", line 185, in call
epsilon=self.epsilon)
File "/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py", line 1864, in normalize_batch_in_training
epsilon=epsilon)
File "/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py", line 1839, in _fused_normalize_batch_in_training
data_format=tf_data_format)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/nn_impl.py", line 1329, in fused_batch_norm
name=name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 4488, in fused_batch_norm_v2
name=name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py", line 626, in _apply_op_helper
param_name=input_name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py", line 60, in _SatisfiesTypeConstraint
", ".join(dtypes.as_dtype(x).name for x in allowed_list)))
TypeError: Value passed to parameter 'scale' has DataType float16 not in list of allowed values: float32

This was a reported bug and upgrading to Keras==2.2.5 solved the issue.

Related

How to resolve "MPS Framework doesn't support float64" on M1 Mac

I am trying to train a YOLO model on a custom dataset using YOLOv8 Ultralytics, using M1 MacBook Pro MPS acceleration which is supported by PyTorch but I am getting the following error while executing the train command.
Command:
!yolo task=detect mode=train model=yolov8s.pt data={HOME}/datasets/data.yaml epochs=25 device=mps
Error Message:
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/cli.py", line 56, in cli
func(cfg)
File "/opt/homebrew/lib/python3.10/site-packages/hydra/main.py", line 79, in decorated_main
return task_function(cfg_passthrough)
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/v8/detect/train.py", line 207, in train
model.train(**cfg)
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/engine/model.py", line 193, in train
self.trainer.train()
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/engine/trainer.py", line 185, in train
self._do_train(int(os.getenv("RANK", -1)), world_size)
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/engine/trainer.py", line 301, in _do_train
self.loss, self.loss_items = self.criterion(preds, batch)
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/v8/detect/train.py", line 77, in criterion
return self.compute_loss(preds, batch)
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/v8/detect/train.py", line 168, in __call__
targets = self.preprocess(targets.to(self.device), batch_size, scale_tensor=imgsz[[1, 0, 1, 0]])
TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.
Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.
Is there any way to get around this issue and use MPS for training?
I have tried looking for this issue on PyTorch's GitHub conversation, but got no simple solution.
Edit:
I have set HYDRA_FULL_ERROR to 1, and this is the updated error traceback:
Error executing job with overrides: ['task=detect', 'mode=train', 'model=yolov8s.pt', 'data=/Users/aditya_nemiwal/Documents/C++/Python/WiDS_Week3_3/datasets/data.yaml', 'epochs=25', 'device=mps']
Traceback (most recent call last):
File "/opt/homebrew/bin/yolo", line 8, in <module>
sys.exit(cli())
File "/opt/homebrew/lib/python3.10/site-packages/hydra/main.py", line 90, in decorated_main
_run_hydra(
File "/opt/homebrew/lib/python3.10/site-packages/hydra/_internal/utils.py", line 394, in _run_hydra
_run_app(
File "/opt/homebrew/lib/python3.10/site-packages/hydra/_internal/utils.py", line 457, in _run_app
run_and_report(
File "/opt/homebrew/lib/python3.10/site-packages/hydra/_internal/utils.py", line 222, in run_and_report
raise ex
File "/opt/homebrew/lib/python3.10/site-packages/hydra/_internal/utils.py", line 219, in run_and_report
return func()
File "/opt/homebrew/lib/python3.10/site-packages/hydra/_internal/utils.py", line 458, in <lambda>
lambda: hydra.run(
File "/opt/homebrew/lib/python3.10/site-packages/hydra/_internal/hydra.py", line 132, in run
_ = ret.return_value
File "/opt/homebrew/lib/python3.10/site-packages/hydra/core/utils.py", line 260, in return_value
raise self._return_value
File "/opt/homebrew/lib/python3.10/site-packages/hydra/core/utils.py", line 186, in run_job
ret.return_value = task_function(task_cfg)
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/cli.py", line 56, in cli
func(cfg)
File "/opt/homebrew/lib/python3.10/site-packages/hydra/main.py", line 79, in decorated_main
return task_function(cfg_passthrough)
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/v8/detect/train.py", line 207, in train
model.train(**cfg)
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/engine/model.py", line 193, in train
self.trainer.train()
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/engine/trainer.py", line 185, in train
self._do_train(int(os.getenv("RANK", -1)), world_size)
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/engine/trainer.py", line 301, in _do_train
self.loss, self.loss_items = self.criterion(preds, batch)
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/v8/detect/train.py", line 77, in criterion
return self.compute_loss(preds, batch)
File "/opt/homebrew/lib/python3.10/site-packages/ultralytics/yolo/v8/detect/train.py", line 168, in __call__
targets = self.preprocess(targets.to(self.device), batch_size, scale_tensor=imgsz[[1, 0, 1, 0]])
TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.

ValueError: Unknown initializer for using keras and tensorflow

I got an error while loading my trained model. My model is about stereo vision, so I used both from tensorflow and keras( not tf.keras).
import numpy as np
import keras
import keras.layers as L
import keras.backend as B
import keras.backend.tensorflow_backend as B_
import keras.activations as A
import tensorflow as tf
Among the code lines I have this :
f_disp = 200
f_d = L.Conv2D(filters=f_disp, kernel_size=(3, 3), strides=1, padding='same')(f_uuu)
f_d = L.BatchNormalization()(f_d)
f_d = L.ReLU()(f_d)
f_d = L.Conv2D(filters=f_disp, kernel_size=(3, 3), strides=1, padding='same')(f_d)
f_d = L.BatchNormalization()(f_d)
f_d = L.ReLU()(f_d)
def disp_filter(shape, dtype=None):
kernel = (np.array(range(f_disp),dtype=np.float32))
kernel = np.tile(kernel,(shape[0]*shape[1]))
kernel = np.reshape(kernel,(shape[0],shape[1],f_disp,1))
print(shape,kernel.shape)
assert kernel.shape == shape
return tf.Variable(kernel,dtype=np.float32)
def sq(x):
sig = A.softmax(x,axis=-1)
f_f = L.Conv2D(filters = 1, kernel_size=(1,1),kernel_initializer=disp_filter,strides=1,padding='same',trainable=False)(sig)
sqx = B.squeeze(f_f,-1)
return sqx
f_sq = L.Lambda(sq)(f_d)
print(f_sq.shape)
return f_sq
Since my layer has more than 300 lines I took only this part.
However When I tried to load model, it outputs error message.
srst = tf.keras.models.load_model(route_weight, compile=True, custom_objects={'disp_filter':disp_filter,'A':keras.activations,'L':keras.layers,'B': keras.backend,'B_':keras.backend.tensorflow_backend,'tf':tf,'maxdsp':192})#,'A':keras.activations})
srst.summary()
This is my load_model code and :
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/eps/venv/test_srstereo.py", line 96, in <module>
srst = tf.keras.models.load_model(route_weight, compile=True, custom_objects={'disp_filter':disp_filter,'A':keras.activations,'L':keras.layers,'B': keras.backend,'B_':keras.backend.tensorflow_backend,'tf':tf,'maxdsp':192})#,'A':keras.activations})
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 146, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 168, in load_model_from_hdf5
custom_objects=custom_objects)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\tensorflow_core\python\keras\saving\model_config.py", line 55, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\tensorflow_core\python\keras\layers\serialization.py", line 102, in deserialize
printable_module_name='layer')
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\tensorflow_core\python\keras\utils\generic_utils.py", line 191, in deserialize_keras_object
list(custom_objects.items())))
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 906, in from_config
config, custom_objects)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 1852, in reconstruct_from_config
process_node(layer, node_data)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 1799, in process_node
output_tensors = layer(input_tensors, **kwargs)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 842, in __call__
outputs = call_fn(cast_inputs, *args, **kwargs)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\tensorflow_core\python\keras\layers\core.py", line 795, in call
return self.function(inputs, **arguments)
File "C:\Users\Administrator\PycharmProjects\eps\venv\stereo_net.py", line 268, in sq
x2_u = L.Concatenate(axis=-1)([x2,x2_u])
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\keras\layers\convolutional.py", line 484, in __init__
**kwargs)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\keras\layers\convolutional.py", line 117, in __init__
self.kernel_initializer = initializers.get(kernel_initializer)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\keras\initializers.py", line 518, in get
return deserialize(config)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\keras\initializers.py", line 510, in deserialize
printable_module_name='initializer')
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\keras\utils\generic_utils.py", line 140, in deserialize_keras_object
': ' + class_name)
ValueError: Unknown initializer: disp_filter
I cannot understand why the error message ValueError: Unknown initializer: disp_filter
occurs since I have never experienced this type of error when I made my network using CNN and backend only. Please tell me what I missed

Keras fit predictions in Callback

I'm trying to get the predictions inside the function on_epoch_end of keras' Callback.
At the moment, to get the predictions, I execute self.model.predict with batch_size of 2, but at the 3rd epochs I get this error:
RuntimeError: Dst tensor is not initialized in Tensorflow
Reading on the web, I notice that this error appears when the GPU goes out of memory. In my case, reading the stack trace, this error is triggered by self.model.predict inside on_epoch_end, it says:
File "mlp_keras.py", line 20, in on_epoch_end predictions =
self.model.predict(self.dataset)
This is the full stack trace:
Traceback (most recent call last):
File "mlp_keras.py", line 150, in <module>
callbacks=[KendallTauHistory(training_dataset, training_dataset_labels, groups_id_count)])
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training.py", line 819, in fit
use_multiprocessing=use_multiprocessing)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 397, in fit
prefix='val_')
File "/usr/lib64/python2.7/contextlib.py", line 24, in __exit__
self.gen.next()
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 771, in on_epoch
self.callbacks.on_epoch_end(epoch, epoch_logs)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/callbacks.py", line 302, in on_epoch_end
callback.on_epoch_end(epoch, logs)
File "mlp_keras.py", line 20, in on_epoch_end
predictions = self.model.predict(self.dataset)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training.py", line 1013, in predict
use_multiprocessing=use_multiprocessing)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 498, in predict
workers=workers, use_multiprocessing=use_multiprocessing, **kwargs)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 426, in _model_iteration
use_multiprocessing=use_multiprocessing)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 706, in _process_inputs
use_multiprocessing=use_multiprocessing)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/data_adapter.py", line 357, in __init__
dataset = self.slice_inputs(indices_dataset, inputs)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/data_adapter.py", line 383, in slice_inputs
dataset_ops.DatasetV2.from_tensors(inputs).repeat()
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/data/ops/dataset_ops.py", line 566, in from_tensors
return TensorDataset(tensors)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/data/ops/dataset_ops.py", line 2765, in __init__
element = structure.normalize_element(element)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/data/util/structure.py", line 113, in normalize_element
ops.convert_to_tensor(t, name="component_%d" % i))
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/framework/ops.py", line 1314, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/framework/tensor_conversion_registry.py", line 52, in _default_conversion_function
return constant_op.constant(value, dtype, name=name)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/framework/constant_op.py", line 258, in constant
allow_broadcast=True)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/framework/constant_op.py", line 266, in _constant_impl
t = convert_to_eager_tensor(value, ctx, dtype)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/framework/constant_op.py", line 96, in convert_to_eager_tensor
return ops.EagerTensor(value, ctx.device_name, dtype)
RuntimeError: Dst tensor is not initialized.
My question is: is there a way to get the predictions without performing predict inside on_epoch_end? Thanks in advance.
Alright, after seeing your last comment, what you could do:
epochs = 100
for epoch in range(epochs):
model.fit(x_train, y_train)
y_predict = model.predict(x_test)

TensorFlow KeyError: 'RegexReplace' when predict on DNNClassifier using tf.contrib.predictor.from_saved_model

I am trying to restore an estimator and predict on it.
System Config :
CentOS 7 - x64 - CPU
tensorflow == 1.5
This is how I saved the estimator DNNClassifier
def serving_input_receiver_fn():
inputs = {"embeddings": tf.placeholder(shape=[None], dtype=tf.string)}
return tf.estimator.export.ServingInputReceiver(inputs, inputs)
export_dir = estimator.export_savedmodel(
export_dir_base='models/run7',
serving_input_receiver_fn=serving_input_receiver_fn)
I reloaded it using tf.contrib.predictor.from_saved_model as follows
estimator = tf.contrib.predictor.from_saved_model('model/1528805269/')
but, then I get the error KeyError: 'RegexReplace' on the above line
complete error :
Traceback (most recent call last):
File "app.py", line 38, in <module>
load_model()
File "app.py", line 21, in load_model
estimator = tf.contrib.predictor.from_saved_model('model/1528805269/')
File "/var/www/html/my_project/prj_v4/lib/python3.6/site-packages/tensorflow/contrib/predictor/predictor_factories.py", line 129, in from_saved_model
graph=graph)
File "/var/www/html/my_project/prj_v4/lib/python3.6/site-packages/tensorflow/contrib/predictor/saved_model_predictor.py", line 156, in __init__
loader.load(self._session, tags.split(','), export_dir)
File "/var/www/html/my_project/prj_v4/lib/python3.6/site-packages/tensorflow/python/saved_model/loader_impl.py", line 216, in load
saver = tf_saver.import_meta_graph(meta_graph_def_to_load, **saver_kwargs)
File "/var/www/html/my_project/prj_v4/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1838, in import_meta_graph
**kwargs)
File "/var/www/html/my_project/prj_v4/lib/python3.6/site-packages/tensorflow/python/framework/meta_graph.py", line 660, in import_scoped_meta_graph
producer_op_list=producer_op_list)
File "/var/www/html/my_project/prj_v4/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 316, in new_func
return func(*args, **kwargs)
File "/var/www/html/my_project/prj_v4/lib/python3.6/site-packages/tensorflow/python/framework/importer.py", line 433, in import_graph_def
_RemoveDefaultAttrs(op_dict, producer_op_list, graph_def)
File "/var/www/html/my_project/prj_v4/lib/python3.6/site-packages/tensorflow/python/framework/importer.py", line 211, in _RemoveDefaultAttrs
op_def = op_dict[node.op]
KeyError: 'RegexReplace'
Any Suggestions what might be going wrong ?

Getting an error when loading the weights of Resnet

I'm trying to load the weights of Resnet loading following code.But inside the Resnet method, when loading the weights
base_model = ResNet50(input_shape=(224, 224, 3), include_top=False,weights='imagenet',pooling='avg')
# load weights
if weights == 'imagenet':
if include_top:
weights_path = get_file('resnet50_weights_tf_dim_ordering_tf_kernels.h5',
WEIGHTS_PATH,
cache_subdir='models',
md5_hash='a7b3fe01876f51b976af0dea6bc144eb')
'''else:
weights_path = get_file('resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5',
WEIGHTS_PATH_NO_TOP,
cache_subdir='models',
md5_hash='a268eb855778b3df3c7506639542a6af')'''
print ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
model.load_weights('C:/Users/hirplk/.keras/models/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5')
print ('cccccccccccccccccccccccccccccccccccccccc')
I'm getting the following error.
Traceback (most recent call last):
File "C:\CT_SCAN_IMAGE_SET\resnet_50\dbs2017\resnet_fineTuning.py", line 391, in <module>
base_model = ResNet50(input_shape=(224, 224, 3), include_top=False,weights='imagenet',pooling='avg')
File "C:\CT_SCAN_IMAGE_SET\resnet_50\dbs2017\resnet_fineTuning.py", line 298, in ResNet50
model.load_weights('C:/Users/hirplk/.keras/models/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5')
File "C:\Research\Python_installation\lib\site-packages\keras\engine\topology.py", line 2622, in load_weights
load_weights_from_hdf5_group(f, self.layers)
File "C:\Research\Python_installation\lib\site-packages\keras\engine\topology.py", line 3143, in load_weights_from_hdf5_group
K.batch_set_value(weight_value_tuples)
File "C:\Research\Python_installation\lib\site-packages\keras\backend\tensorflow_backend.py", line 2247, in batch_set_value
assign_op = x.assign(assign_placeholder)
File "C:\Research\Python_installation\lib\site-packages\tensorflow\python\ops\variables.py", line 527, in assign
return state_ops.assign(self._variable, value, use_locking=use_locking)
File "C:\Research\Python_installation\lib\site-packages\tensorflow\python\ops\state_ops.py", line 274, in assign
validate_shape=validate_shape)
File "C:\Research\Python_installation\lib\site-packages\tensorflow\python\ops\gen_state_ops.py", line 43, in assign
use_locking=use_locking, name=name)
File "C:\Research\Python_installation\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 767, in apply_op
op_def=op_def)
File "C:\Research\Python_installation\lib\site-packages\tensorflow\python\framework\ops.py", line 2632, in create_op
set_shapes_for_outputs(ret)
File "C:\Research\Python_installation\lib\site-packages\tensorflow\python\framework\ops.py", line 1911, in set_shapes_for_outputs
shapes = shape_func(op)
File "C:\Research\Python_installation\lib\site-packages\tensorflow\python\framework\ops.py", line 1861, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "C:\Research\Python_installation\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 595, in call_cpp_shape_fn
require_shape_fn)
File "C:\Research\Python_installation\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 659, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: Dimension 0 in both shapes must be equal, but are 1 and 512 for 'Assign_78' (op: 'Assign') with input shapes: [1,1,128,512], [512,256,1,1].
My images are with dimension [224,224,3].
Can someone please help me to identify what my issue is?
It seems you are using Keras to load RESNET weights. Keras needs to specify the channels order, which sometimes get mixed up. Try to use:
K.set_image_data_format('channels_last')
Look here for more details: https://keras.io/backend/#set_image_data_format

Categories