Comments (7)
Hi there! Thanks for raising this issue. To help reproduce/diagnose, could you please provide the following?
- A full traceback of the error
- The output of the following code snippet
import vit_keras
import tensorflow as tf
import tensorflow_addons as tfa
print("vit_keras", vit_keras.__version__)
print("tensorflow", tf.__version__)
print("tensorflow-addons", tfa.__version__)
As a quick fix in the meantime, I suggest trying tensorflow
>= 2.3.0 with a compatible version of tensorflow-addons
(see compatibility matrix).
from vit-keras.
Certainly.
I will try,the information is followed.
-
The full traceback of the error
File "vit-keras-master/vit_keras/vit.py", line 146, in vit_b16
representation_size=768 if weights == "imagenet21k" else None,
File "vit-keras-master/vit_keras/vit.py", line 77, in build_model
y = layers.AddPositionEmbs(y.shape,name="Transformer/posembed_input")(y)
File "anaconda3/envs/vit3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 817, in __call__
self._maybe_build(inputs)
File "anaconda3/envs/vit3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 2141, in _maybe_build
self.build(input_shapes)
File "vit-keras-master/vit_keras/layers.py", line 38, in build
shape=(1,input_shape[1],input_shape[2])
File "anaconda3/envs/vit3/lib/python3.7/site-packages/tensorflow_core/python/ops/init_ops_v2.py", line 296, in __call__
dtype)
File "anaconda3/envs/vit3/lib/python3.7/site-packages/tensorflow_core/python/ops/init_ops_v2.py", line 791, in random_normal
shape=shape, mean=mean, stddev=stddev, dtype=dtype, seed=self.seed)
File "anaconda3/envs/vit3/lib/python3.7/site-packages/tensorflow_core/python/ops/random_ops.py", line 69, in random_normal
shape_tensor = tensor_util.shape_tensor(shape)
File "anaconda3/envs/vit3/lib/python3.7/site-packages/tensorflow_core/python/framework/tensor_util.py", line 964, in shape_tensor
return ops.convert_to_tensor(shape, dtype=dtype, name="shape")
File "anaconda3/envs/vit3/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1184, in convert_to_tensor
return convert_to_tensor_v2(value, dtype, preferred_dtype, name)
File "anaconda3/envs/vit3/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1242, in convert_to_tensor_v2
as_ref=False)
File "anaconda3/envs/vit3/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1296, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "anaconda3/envs/vit3/lib/python3.7/site-packages/tensorflow_core/python/framework/constant_op.py", line 286, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "anaconda3/envs/vit3/lib/python3.7/site-packages/tensorflow_core/python/framework/constant_op.py", line 227, in constant
allow_broadcast=True)
File "anaconda3/envs/vit3/lib/python3.7/site-packages/tensorflow_core/python/framework/constant_op.py", line 235, in _constant_impl
t = convert_to_eager_tensor(value, ctx, dtype)
File "anaconda3/envs/vit3/lib/python3.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)
ValueError: Can't convert Python sequence with mixed types to Tensor.
- The output of the following code snippet
vit_keras 0.0.0
tensorflow 2.0.0
tensorflow-addons 0.6.0
from vit-keras.
I haven't been able to reproduce this yet. Could you provide the code that yields the exception (i.e., the arguments you're providing to vit_b16
)?
from vit-keras.
Environment:tensorflow2.0.0 cuda:10.0 cudnn:7.6.4
I just run the demo on the https://github.com/faustomorales/vit-keras, don't change anything.
from vit_keras import vit, utils
image_size = 384
classes = utils.get_imagenet_classes()
model = vit.vit_b16(
image_size=image_size,
activation='sigmoid',
pretrained=True,
include_top=True,
pretrained_top=True
)
url = 'https://upload.wikimedia.org/wikipedia/commons/d/d7/Granny_smith_and_cross_section.jpg'
image = utils.read(url, image_size)
X = vit.preprocess_inputs(image).reshape(1, image_size, image_size, 3)
y = model.predict(X)
print(classes[y[0].argmax()]) # Granny smith
The frist error i got is the “tf.initializers.random_normal” ,the module is not found.
So i change the module to "tf.random_normal_initializer".
I got the error “ValueError: Can't convert Python sequence with mixed types to Tensor. ” as mentioned above.
Also,i try some other modules like "tf.random.normal", but still get the error “ValueError: Can't convert Python sequence with mixed types to Tensor. ”
But i have found the reason.
In vit.py line 76,the output shape of the 'tf.keras.layers.Reshape((-1, hidden_size))(y)' is
**[None,None,768]**
after the 'layers.ClassToken(name="class_token")(y)' line 77, the output is still
**[None,None,768]**
The second element dimension is None,so in the “ y = layers.AddPositionEmbs(name="Transformer/posembed_input")(y)”,
the error “ValueError: Can't convert Python sequence with mixed types to Tensor. ” happens. So i change the
**tf.keras.layers.Reshape((-1, hidden_size))(y) to y = tf.keras.layers.Reshape((y.shape[1]*y.shape[2], hidden_size))(y)**
And it works
from vit-keras.
Nice! This fix has been applied as of a59b999 and is in v0.0.10 on PyPi.
from vit-keras.
I have encountered a problem showing the same error as the below example. I would appreciate any help in this matter.
Summary:
- List of Tuple containing (1,2) can be converted to a TensorFlow variable.
- List of Tuple containing (3, (6, 9)) can NOT be converted to a TensorFlow variable.
t1 = []
for i in range(10):
... t1.append((i, 2i))
...
t1
[(0, 0), (1, 2), (2, 4), (3, 6), (4, 8), (5, 10), (6, 12), (7, 14), (8, 16), (9, 18)]
t1_tv = tf.Variable(t1, dtype=tf.int32)
t1_tv
<tf.Variable 'Variable:0' shape=(10, 2) dtype=int32, numpy=
array([[ 0, 0],
[ 1, 2],
[ 2, 4],
[ 3, 6],
[ 4, 8],
[ 5, 10],
[ 6, 12],
[ 7, 14],
[ 8, 16],
[ 9, 18]], dtype=int32)>
t2 = []
for i in range(10):
... t2.append((i, (2i, i**2)))
...
t2
[(0, (0, 0)), (1, (2, 1)), (2, (4, 4)), (3, (6, 9)), (4, (8, 16)), (5, (10, 25)), (6, (12, 36)), (7, (14, 49)), (8, (16, 64)), (9, (18, 81))]
t2_tv = tf.Variable(t2, dtype=tf.int32)
Traceback (most recent call last):
File "", line 1, in
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/ops/variables.py", line 268, in call
return cls._variable_v2_call(*args, **kwargs)
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/ops/variables.py", line 250, in _variable_v2_call
return previous_getter(
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/ops/variables.py", line 243, in
previous_getter = lambda **kws: default_variable_creator_v2(None, **kws)
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/ops/variable_scope.py", line 2662, in default_variable_creator_v2
return resource_variable_ops.ResourceVariable(
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/ops/variables.py", line 270, in call
return super(VariableMetaclass, cls).call(*args, **kwargs)
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 1602, in init
self._init_from_args(
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 1745, in _init_from_args
initial_value = ops.convert_to_tensor(initial_value,
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/profiler/trace.py", line 163, in wrapped
return func(*args, **kwargs)
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/framework/ops.py", line 1566, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 346, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 271, in constant
return _constant_impl(value, dtype, shape, name, verify_shape=False,
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 283, in _constant_impl
return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 308, in _constant_eager_impl
t = convert_to_eager_tensor(value, ctx, dtype)
File "/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 106, in convert_to_eager_tensor
return ops.EagerTensor(value, ctx.device_name, dtype)
ValueError: Can't convert Python sequence with mixed types to Tensor.
from vit-keras.
b = [[float('nan'), 2, 3, 0, "s"],
[0, 0, float('nan'), 4, 5],
[45, float('nan'), 3, 4, float('nan')]]
b = tf.strings.as_string(b)
print(b)
Can't convert Python sequence with mixed types to Tensor.
from vit-keras.
Related Issues (20)
- how to get the official pretrain model with npz format? HOT 1
- The [call] method in TransformerBlock has different input args HOT 1
- grayscale images HOT 1
- Multilabel: class-wise attention maps HOT 2
- image size HOT 1
- weights file failed to load ("File is not a zip file") HOT 2
- load_pretrained - BASE_URL 404 Not Found HOT 3
- different image size in fine-tuning HOT 3
- Different number of channels HOT 3
- error with visualization HOT 1
- Visualization of transfer learning model
- can you public a url to download the offcial weights? HOT 1
- load fine-tuned model with keras.load_model HOT 4
- Interest in implementing pre-trained weights from "ImageNet-21K Pretraining for the Masses" to vit-keras HOT 1
- Meaning of FlexErf node
- No requirements file makes compatibility issues challenging to debug. HOT 1
- Minimum image size to use pretrained weights HOT 1
- Finetuning
- Error importing the model HOT 1
- ModuleNotFoundError: No module named 'keras.src.engine' HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vit-keras.