質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

1回答

1876閲覧

TypeError: int() argument must be a string, a bytes-like object or a number, not 'Tensor'

MMYY

総合スコア0

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2020/08/08 09:46

編集2020/08/09 03:34

前提・実現したいこと

sytlegan2で画像の自動生成をしようとしていますがエラーでてうまくいきません。どなたかご教授お願い致します。

発生している問題・エラーメッセージ

Setting up TensorFlow plugin "fused_bias_act.cu": Preprocessing... Loading... Done. --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-4-3b492798ead6> in <module> 1 if __name__ == "__main__": ----> 2 generate_image() <ipython-input-3-92ea8bd920cd> in generate_image() 21 # 2020-01-11-skylion-stylegan2-animeportraits-networksnapshot-024664.pkl (https://www.gwern.net/Faces#stylegan-2) 22 with open("network-snapshot-017325.pkl", "rb") as f: ---> 23 _, _, Gs = pickle.load(f) 24 # Gs = Long-term average of the generator. Yields higher-quality results than the instantaneous snapshot. 25 ~\AnacondaProjects\stylegan2-master\dnnlib\tflib\network.py in __setstate__(self, state) 295 296 # Init TensorFlow graph. --> 297 self._init_graph() 298 self.reset_own_vars() 299 tfutil.set_vars({self.find_var(name): value for name, value in state["variables"]}) ~\AnacondaProjects\stylegan2-master\dnnlib\tflib\network.py in _init_graph(self) 152 with tf.control_dependencies(None): # ignore surrounding control dependencies 153 self.input_templates = [tf.placeholder(tf.float32, name=name) for name in self.input_names] --> 154 out_expr = self._build_func(*self.input_templates, **build_kwargs) 155 156 # Collect outputs. <string> in G_synthesis_stylegan2(dlatents_in, dlatent_size, num_channels, resolution, fmap_base, fmap_decay, fmap_min, fmap_max, randomize_noise, architecture, nonlinearity, dtype, resample_kernel, fused_modconv, **_kwargs) <string> in block(x, res) <string> in layer(x, layer_idx, fmaps, kernel, up) <string> in modulated_conv2d_layer(x, y, fmaps, kernel, up, down, demodulate, resample_kernel, gain, use_wscale, lrmul, fused_modconv, weight_var, mod_weight_var, mod_bias_var) ~\AnacondaProjects\stylegan2-master\dnnlib\tflib\ops\upfirdn_2d.py in upsample_conv_2d(x, w, k, factor, gain, data_format, impl) 289 290 # Execute. --> 291 x = tf.nn.conv2d_transpose(x, w, output_shape=output_shape, strides=stride, padding='VALID', data_format=data_format) 292 return _simple_upfirdn_2d(x, k, pad0=(p+1)//2+factor-1, pad1=p//2+1, data_format=data_format, impl=impl) 293 ~\anaconda3\envs\tfl113 gpu\lib\site-packages\tensorflow\python\ops\nn_ops.py in conv2d_transpose(value, filter, output_shape, strides, padding, data_format, name) 1635 # output_shape's shape should be == [4] if reached this point. 1636 if not filter.get_shape().dims[2].is_compatible_with( -> 1637 output_shape[axis]): 1638 raise ValueError( 1639 "output_shape does not match filter's output channels, " ~\anaconda3\envs\tfl113 gpu\lib\site-packages\tensorflow\python\framework\tensor_shape.py in is_compatible_with(self, other) 246 True if this Dimension and `other` are compatible. 247 """ --> 248 other = as_dimension(other) 249 return (self._value is None or other.value is None or 250 self._value == other.value) ~\anaconda3\envs\tfl113 gpu\lib\site-packages\tensorflow\python\framework\tensor_shape.py in as_dimension(value) 630 return value 631 else: --> 632 return Dimension(value) 633 634 ~\anaconda3\envs\tfl113 gpu\lib\site-packages\tensorflow\python\framework\tensor_shape.py in __init__(self, value) 183 raise TypeError("Cannot convert %s to Dimension" % value) 184 else: --> 185 self._value = int(value) 186 if (not isinstance(value, compat.bytes_or_text_types) and 187 self._value != value): TypeError: int() argument must be a string, a bytes-like object or a number, not 'Tensor'

該当のソースコード

Python3

1import os 2import pickle 3import numpy as np 4import PIL.Image 5import dnnlib.tflib as tflib 6from datetime import datetime 7 8# number of create StyleGAN image file 9IMAGE_NUM = 30 10# number of split frame two GAN files for changing image 11SPLIT_NUM = 19 12# image size 13IMG_SIZE = 512 14FILENAME_PREFIX = datetime.now().strftime("%Y%m%d%H%M%S") 15 16def generate_image(): 17 """Generate GAN Image """ 18 # Initialize TensorFlow. 19 tflib.init_tf() 20 21 # 2020-01-11-skylion-stylegan2-animeportraits-networksnapshot-024664.pkl (https://www.gwern.net/Faces#stylegan-2) 22 with open("network-snapshot-017325.pk", "rb") as f: 23 _, _, Gs = pickle.load(f) 24 # Gs = Long-term average of the generator. Yields higher-quality results than the instantaneous snapshot. 25 26 # Print network details. 27 Gs.print_layers() 28 29 # Pick latent vector. 30 rnd = np.random.RandomState() 31 32 # create latents stacks because of changing several latents vectors. 33 for i in range(IMAGE_NUM): 34 latents = rnd.randn(1, Gs.input_shape[1]) 35 if i == 0: 36 stacked_latents = latents 37 else: 38 stacked_latents = np.vstack([stacked_latents, latents]) 39 40 for i in range(len(stacked_latents) - 1): 41 latents_before = stacked_latents[i].reshape(1, -1) 42 latents_after = stacked_latents[i + 1].reshape(1, -1) 43 for j in range(SPLIT_NUM + 1): 44 latents = latents_before + (latents_after - latents_before) * j / SPLIT_NUM 45 fmt = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True) 46 images = Gs.run(latents, None, truncation_psi=0.7, randomize_noise=True, output_transform=fmt) 47 os.makedirs("results", exist_ok=True) 48 png_filename = os.path.join("results", FILENAME_PREFIX + "-{0:04d}-{1:04d}".format(i, j + 1) + ".png") 49 PIL.Image.fromarray(images[0], 'RGB').save(png_filename) 50 51 52 53if __name__ == "__main__": 54 generate_image()

試したこと

tensorflowのバージョンを2.0にすると解決できると紹介しているサイトを見つけ実行してみたがダメだった。

補足情報(FW/ツールのバージョンなど)

Windows 10
Tensorflow 1.13.1
CUDA 10.0.
cuDNN 7.3

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

meg_

2020/08/08 10:30

> tensorflowのバージョンを2.0にすると解決できると紹介しているサイトを見つけ実行 どのサイトでしょうか?
meg_

2020/08/08 10:36

エラーメッセージでは > with open("network-snapshot-017325.pkl", "rb") as f: ですが、質問のコード中では > with open("2020-01-11-skylion-stylegan2-animeportraits-networksnapshot-024664.pkl", "rb") as f: となっています。 エラーが発生したコードと質問のコードは別のものではありませんか?
MMYY

2020/08/09 03:35

ご指摘ありがとうございます。編集しました。 "2020-01-11-skylion-stylegan2-animeportraits-networksnapshot-024664.pkl"はもとファイルが.pkl.xzで拡張子を変えていたのでそこが悪いと思いもとからpklであるファイルを使ってみました。 質問コードは引用元からそのまま引っ張ってきたので異なってしまっていました。
meg_

2020/08/09 04:10

pklファイルが読み込めてないのですよね? そのファイルはどうやって作成されましたか?
MMYY

2020/08/09 10:59

エラーの意味が分からないので、pklファイルが読め込めてないかは分かりません。自分で勝手に可能性の一つとして考えてみただけです。ファイルはコードの参照元で利用されているものを使用しています。(2通りの配布方法があり、配布方法にファイル名は違うが中身は変わらない)
meg_

2020/08/09 11:24

> ファイルはコードの参照元で利用されているものを使用しています。(2通りの配布方法があり、配布方法にファイル名は違うが中身は変わらない) 「コードの参照元」って何のことでしょうか? こちらは質問に書いてあることしか情報がありませんので、質問のコードが引用したものであるなら引用元に質問されるのが最適かと思います。
guest

回答1

0

google翻訳
TypeError: int()引数は、'Tensor'ではなく、文字列、バイトのようなオブジェクトまたは数値でなければなりません

投稿2020/08/08 10:50

y_waiwai

総合スコア87774

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問