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

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

新規登録して質問してみよう
ただいま回答率
85.48%
Google Colaboratory

Google Colaboratoryとは、無償のJupyterノートブック環境。教育や研究機関の機械学習の普及のためのGoogleの研究プロジェクトです。PythonやNumpyといった機械学習で要する大方の環境がすでに構築されており、コードの記述・実行、解析の保存・共有などが可能です。

Python 3.x

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

Q&A

0回答

793閲覧

Colabを使った機械学習について

Pleiades0878

総合スコア1

Google Colaboratory

Google Colaboratoryとは、無償のJupyterノートブック環境。教育や研究機関の機械学習の普及のためのGoogleの研究プロジェクトです。PythonやNumpyといった機械学習で要する大方の環境がすでに構築されており、コードの記述・実行、解析の保存・共有などが可能です。

Python 3.x

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

0グッド

0クリップ

投稿2022/09/06 13:53

使用環境

Google Colab

実行時のコード
!python train.py --dataroot ./datasets/2200 --name 2200_batch_16 --label_nc 0 --no_instance --save_latest_freq 2200 --save_epoch_freq 100 --use_dropout --batchSize 16 --tf_log --lr 0.00005

やりたいこと

Google Colab上でPix2PixHDを用いて学習
tensorboardを使いたいためtensorflowを使用

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

tensorboardを使いたいためtensorflowを用いてるのですが以下のようなエラーが出ており,対象方がわかりません.
AttributeError: module 'tensorflow' has no attribute 'Summary'

------------ Options ------------- batchSize: 16 beta1: 0.5 checkpoints_dir: ./checkpoints continue_train: False data_type: 32 dataroot: ./datasets/2200 debug: False display_freq: 100 display_winsize: 512 feat_num: 3 fineSize: 512 fp16: False gpu_ids: [0] input_nc: 3 instance_feat: False isTrain: True label_feat: False label_nc: 0 lambda_feat: 10.0 loadSize: 1024 load_features: False load_pretrain: local_rank: 0 lr: 5e-05 max_dataset_size: inf model: pix2pixHD nThreads: 2 n_blocks_global: 9 n_blocks_local: 3 n_clusters: 10 n_downsample_E: 4 n_downsample_global: 4 n_layers_D: 3 n_local_enhancers: 1 name: 2200_batch_16 ndf: 64 nef: 16 netG: global ngf: 64 niter: 100 niter_decay: 100 niter_fix_global: 0 no_flip: False no_ganFeat_loss: False no_html: False no_instance: True no_lsgan: False no_vgg_loss: False norm: instance num_D: 2 output_nc: 3 phase: train pool_size: 0 print_freq: 100 resize_or_crop: scale_width save_epoch_freq: 100 save_latest_freq: 2200 serial_batches: False tf_log: True use_dropout: True verbose: False which_epoch: latest -------------- End ---------------- (scale1_layer4): Sequential( (0): Conv2d(512, 1, kernel_size=(4, 4), stride=(1, 1), padding=(2, 2)) ) (downsample): AvgPool2d(kernel_size=3, stride=2, padding=[1, 1]) ) /usr/local/lib/python3.7/dist-packages/torchvision/models/_utils.py:209: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and will be removed in 0.15, please use 'weights' instead. f"The parameter '{pretrained_param}' is deprecated since 0.13 and will be removed in 0.15, " /usr/local/lib/python3.7/dist-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passing `weights=VGG19_Weights.IMAGENET1K_V1`. You can also use `weights=VGG19_Weights.DEFAULT` to get the most up-to-date weights. warnings.warn(msg) 2022-09-06 13:31:55.624112: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:39] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0. create web directory ./checkpoints/2200_batch_16/web... (epoch: 1, iters: 300, time: 0.555) G_GAN: 0.676 G_GAN_Feat: 3.975 G_VGG: 4.539 D_real: 0.624 D_fake: 0.616 Traceback (most recent call last): File "train.py", line 104, in <module> visualizer.plot_current_errors(errors, total_steps) File "/content/drive/MyDrive/pix2pixHD/util/visualizer.py", line 99, in plot_current_errors summary = self.tf.Summary(value=[self.tf.Summary.Value(tag=tag, simple_value=value)]) AttributeError: module 'tensorflow' has no attribute 'Summary'

該当のソースコード

python

1import numpy as np 2import os 3import ntpath 4import time 5from . import util 6from . import html 7import scipy.misc 8try: 9 from StringIO import StringIO # Python 2.7 10except ImportError: 11 from io import BytesIO # Python 3.x 12 13class Visualizer(): 14 def __init__(self, opt): 15 # self.opt = opt 16 self.tf_log = opt.tf_log 17 self.use_html = opt.isTrain and not opt.no_html 18 self.win_size = opt.display_winsize 19 self.name = opt.name 20 if self.tf_log: 21 import tensorflow as tf 22 self.tf = tf 23 self.log_dir = os.path.join(opt.checkpoints_dir, opt.name, 'logs') 24 # self.writer = tf.summary.FileWriter(self.log_dir) 25 self.writer = tf.summary.create_file_writer(self.log_dir) 26 27 if self.use_html: 28 self.web_dir = os.path.join(opt.checkpoints_dir, opt.name, 'web') 29 self.img_dir = os.path.join(self.web_dir, 'images') 30 print('create web directory %s...' % self.web_dir) 31 util.mkdirs([self.web_dir, self.img_dir]) 32 self.log_name = os.path.join(opt.checkpoints_dir, opt.name, 'loss_log.txt') 33 with open(self.log_name, "a") as log_file: 34 now = time.strftime("%c") 35 log_file.write('================ Training Loss (%s) ================\n' % now) 36 37 # |visuals|: dictionary of images to display or save 38 def display_current_results(self, visuals, epoch, step): 39 if self.tf_log: # show images in tensorboard output 40 img_summaries = [] 41 for label, image_numpy in visuals.items(): 42 # Write the image to a string 43 try: 44 s = StringIO() 45 except: 46 s = BytesIO() 47 scipy.misc.toimage(image_numpy).save(s, format="jpeg") 48 # Create an Image object 49 img_sum = self.tf.Summary.Image(encoded_image_string=s.getvalue(), height=image_numpy.shape[0], width=image_numpy.shape[1]) 50 # Create a Summary value 51 img_summaries.append(self.tf.Summary.Value(tag=label, image=img_sum)) 52 53 # Create and write Summary 54 summary = self.tf.Summary(value=img_summaries) 55 self.writer.add_summary(summary, step) 56 57 if self.use_html: # save images to a html file 58 for label, image_numpy in visuals.items(): 59 if isinstance(image_numpy, list): 60 for i in range(len(image_numpy)): 61 img_path = os.path.join(self.img_dir, 'epoch%.3d_%s_%d.jpg' % (epoch, label, i)) 62 util.save_image(image_numpy[i], img_path) 63 else: 64 img_path = os.path.join(self.img_dir, 'epoch%.3d_%s.jpg' % (epoch, label)) 65 util.save_image(image_numpy, img_path) 66 67 # update website 68 webpage = html.HTML(self.web_dir, 'Experiment name = %s' % self.name, refresh=30) 69 for n in range(epoch, 0, -1): 70 webpage.add_header('epoch [%d]' % n) 71 ims = [] 72 txts = [] 73 links = [] 74 75 for label, image_numpy in visuals.items(): 76 if isinstance(image_numpy, list): 77 for i in range(len(image_numpy)): 78 img_path = 'epoch%.3d_%s_%d.jpg' % (n, label, i) 79 ims.append(img_path) 80 txts.append(label+str(i)) 81 links.append(img_path) 82 else: 83 img_path = 'epoch%.3d_%s.jpg' % (n, label) 84 ims.append(img_path) 85 txts.append(label) 86 links.append(img_path) 87 if len(ims) < 10: 88 webpage.add_images(ims, txts, links, width=self.win_size) 89 else: 90 num = int(round(len(ims)/2.0)) 91 webpage.add_images(ims[:num], txts[:num], links[:num], width=self.win_size) 92 webpage.add_images(ims[num:], txts[num:], links[num:], width=self.win_size) 93 webpage.save() 94 95 # errors: dictionary of error labels and values 96 def plot_current_errors(self, errors, step): 97 if self.tf_log: 98 for tag, value in errors.items(): 99 # summary = self.tf.Summary(value=[self.tf.Summary.Value(tag=tag, simple_value=value)]) 100 summary = self.tf.summary.create_file_writer(value=[self.tf.compat.v2.Summary.Value(tag=tag, simple_value=value)]) 101 102 self.writer.add_summary(summary, step) 103 104 # errors: same format as |errors| of plotCurrentErrors 105 def print_current_errors(self, epoch, i, errors, t): 106 message = '(epoch: %d, iters: %d, time: %.3f) ' % (epoch, i, t) 107 for k, v in errors.items(): 108 if v != 0: 109 message += '%s: %.3f ' % (k, v) 110 111 print(message) 112 with open(self.log_name, "a") as log_file: 113 log_file.write('%s\n' % message) 114 115 # save image to the disk 116 def save_images(self, webpage, visuals, image_path): 117 image_dir = webpage.get_image_dir() 118 short_path = ntpath.basename(image_path[0]) 119 name = os.path.splitext(short_path)[0] 120 121 webpage.add_header(name) 122 ims = [] 123 txts = [] 124 links = [] 125 126 for label, image_numpy in visuals.items(): 127 image_name = '%s_%s.jpg' % (name, label) 128 save_path = os.path.join(image_dir, image_name) 129 util.save_image(image_numpy, save_path) 130 131 ims.append(image_name) 132 txts.append(label) 133 links.append(image_name) 134 webpage.add_images(ims, txts, links, width=self.win_size) 135

試したこと

tensorflowのバージョン違いによる書き換えが必要という記事を読み修正したのですが,変更後もエラーが出ます

補足

tensorboard 2.8.0
tensorflow 2.8.2

です

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

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

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

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

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

jbpb0

2022/09/07 05:34 編集

質問に記載のコードは https://github.com/NVIDIA/pix2pixHD/blob/master/util/visualizer.py のようですが、これの日付はLatest commit 5a2c872 on 14 Jun 2019で、tensorflow 2.0 https://pypi.org/project/tensorflow/2.0.0/ のリリース日のReleased: Oct 1, 2019よりも前なので、tensorflow 1.*用に書かれたものだと思うので、google colabにtensorflow 1.*を入れたら、この質問のエラーは出なくなるのではないですかね https://prglog.info/home/?p=22
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問