Input shape of image for the classifiers is wrong
I downloaded the 40 classifiers here, but when i try to run it on an image it gives strange exceptions.
If i run the classifier with:
classifier.run( image , None )
where image is:
image = np.asarray(Image.open('drive/MyDrive/sample_img.jpg').resize((256,256) ) #(256, 256, 3)
image = np.expand_dims(image, axis=0) #(1, 256, 256, 3) = (NWHC)
image = convert_images_from_uint8(images=image,nhwc_to_nchw=True) #(1, 3, 256, 256) = (NCHW)
( NB: convert_images_from_uint8 defined here )
this error comes:
_UnimplementedError (see above for traceback): Generic conv implementation only supports NHWC tensor format for now.
[[node celebahq-classifier-20-goatee/Run/celebahq-classifier-20-goatee/FromRGB_lod0/Conv2D (defined at
But if i comment the function convert_images_from_uint8, thus giving an NWHC image, this arises:
_InvalidArgumentError: input depth must be evenly divisible by filter depth: 256 vs 3 [[{{node celebahq-classifier-20-goatee/Run/celebahq-classifier-20-goatee/FromRGB_lod0/Conv2D}}]]
It seems to me that there are some problems/confusion among the dimensions, since the 256 appearing in the error is not a random number. How can i fix it?
I even tried to use
logits = classifier.get_output_for( image , None )
>>> print(logits)
>>> <tf.Tensor 'celebahq-classifier-00-male_1/scores_out:0' shape=(1, 1) dtype=float32>
predictions = tf.nn.softmax(tf.concat([logits, -logits], axis=1))
>>> print(predictions)
>>> <tf.Tensor 'Softmax:0' shape=(1, 2) dtype=float32>
as the authors did in the original StyleGAN2 paper repo here but i end up with a tf.Tensor from which i am not able to retrieve the classifier's value
We provide codes for running the classifiers in GetAttribute.py. Please refer to DCI '3 annotate the images using pretrained classifers' for how to use the GetAttribute.py.
Specifically, in line 67-69
tmp_imgs=imgs[(i*batch_size):((i+1)*batch_size)] #imgs is a numpy array of shape (n, h, w, 3)
tmp_imgs=convert_images_from_uint8(tmp_imgs, drange=[-1,1], nhwc_to_nchw=True)
tmp = classifier.run(tmp_imgs, None)
Using GetAttribute.py it just gives me zeros for all the classes, even if i provide a clear example of a male and a female. Isn't it strange? (but at least it works, don't know how)
I already tried the exact code you just posted in my first code snippet of this issue here; i repost it to be more similar to yours:
i = 0
batch_size = 2
image1 = np.asarray( Image.open('drive/MyDrive/sample_img.jpg').resize((256,256)) )
image2 = np.asarray( Image.open('drive/MyDrive/sample_img2.jpg').resize((256,256)) )
imgs = np.array([image1,image2]) #(2,256,256,3)
np.save('imgs.npy', imgs)
imgs = np.load('imgs.npy') #(2,256,256,3)
for classifier in classifiers:
tmp_imgs = imgs[(i*batch_size):((i+1)*batch_size)] #(2,256,256,3)
tmp_imgs = convert_images_from_uint8(tmp_imgs, drange=[-1,1], nhwc_to_nchw=True) #(2,3,256,256)
tmp = classifier.run( tmp_imgs , None)
and the result remains the same:
_UnimplementedError (see above for traceback): Generic conv implementation only supports NHWC tensor format for now.
or
_InvalidArgumentError: input depth must be evenly divisible by filter depth: 256 vs 3 if i comment line 68
I replied, since the issue remains. Thanks for your time, i attend your response, FR.
Da: Zongze @.> Inviato: domenica 27 novembre 2022 16:11 A: @.> Cc: Federico @.>; @.> Oggetto: Re: [betterze/StyleSpace] Input shape of image for the classifiers is wrong (Issue #32)
We provide codes for running the classifiers in GetAttribute.pyhttps://github.com/betterze/StyleSpace/blob/main/GetAttribute.py. Please refer to DCIhttps://github.com/betterze/StyleSpace#dci-metric '3 annotate the images using pretrained classifers' for how to use the GetAttribute.py.
Specifically, in line 67-69https://github.com/betterze/StyleSpace/blob/main/GetAttribute.py#L67
tmp_imgs=imgs[(i*batch_size):((i+1)*batch_size)] #imgs is a numpy array of shape (n, h, w, 3)
tmp_imgs=convert_images_from_uint8(tmp_imgs, drange=[-1,1], nhwc_to_nchw=True)
tmp = classifier.run(tmp_imgs, None)
— Reply to this email directly, view it on GitHubhttps://github.com/betterze/StyleSpace/issues/32#issuecomment-1328266730, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOWYJQQSOIWHQUICKVRYCHLWKN2ZNANCNFSM6AAAAAASLRB3JA. You are receiving this because you authored the thread.Message ID: @.***>
Are you using tensorflow gpu version? I believe the error is caused by tensorflow cpu version.
I'm using tensorflow cpu version since i don't have a physical GPU but i rely on Google Colab's. In a couple of days i will be provided one, so i will try with that!
Which version of tf-gpu should i use? I remember some of your code needed tensorflow 1.x, so in colab i installed manually
pip install tensorflow 1.13.2
I use tf 1.14.
Even doing ! pip install tensorflow-gpu==1.14 the result remains the same... whereas by running the script GetAttribute.py ii works but i obtain only zeros. Any suggestions?
In the meanwhile can you at least share the attribute.csv file in the complete version? I mean with 40 columns, one for classifier, since the one uploaded only has 15.
And which are the header rows (images)? I followed the generation procedure from GetCode.py, they are generated from W.npy. Are there any ways i can trace them back?
Any hints?