tensorflow / tensorboard

TensorFlow's Visualization Toolkit
Apache License 2.0
6.7k stars 1.66k forks source link

AttributeError: 'Logger' object has no attribute 'writer' #6919

Closed abiotik closed 3 weeks ago

abiotik commented 1 month ago

Consider Stack Overflow for getting support using TensorBoard—they have a larger community with better searchability:

Diagnostics output
--- check: autoidentify
INFO: diagnose_tensorboard.py version c6ca9f1d004e2a1bc7c160abc43be229b82cad7e

--- check: general
INFO: sys.version_info: sys.version_info(major=3, minor=6, micro=15, releaselevel='final', serial=0)
INFO: os.name: posix
INFO: os.uname(): posix.uname_result(sysname='Linux', nodename='rack2', release='6.1.0-18-amd64', version='#1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 (2024-02-01)', machine='x86_64')
INFO: sys.getwindowsversion(): N/A

--- check: package_management
INFO: has conda-meta: True
INFO: $VIRTUAL_ENV: None

--- check: installed_packages
INFO: installed: tensorboard==2.10.1
INFO: installed: tensorflow-gpu==2.5.0
INFO: installed: tensorflow-estimator==2.5.0
INFO: installed: tensorboard-data-server==0.6.1

--- check: tensorboard_python_version
INFO: tensorboard.version.VERSION: '2.10.1'

--- check: tensorflow_python_version
2024-09-25 17:42:14.527256: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0
INFO: tensorflow.__version__: '2.5.0'
INFO: tensorflow.__git_version__: 'v2.5.0-rc3-213-ga4dfb8d1a71'

--- check: tensorboard_data_server_version
INFO: data server binary: '/home/nikola/opt/anaconda3/envs/gen/lib/python3.6/site-packages/tensorboard_data_server/bin/server'
Traceback (most recent call last):
  File "diagnose_tensorboard.py", line 511, in main
    suggestions.extend(check())
  File "diagnose_tensorboard.py", line 81, in wrapper
    result = fn()
  File "diagnose_tensorboard.py", line 290, in tensorboard_data_server_version
    check=True,
  File "/home/nikola/opt/anaconda3/envs/gen/lib/python3.6/subprocess.py", line 423, in run
    with Popen(*popenargs, **kwargs) as process:
TypeError: __init__() got an unexpected keyword argument 'capture_output'

--- check: tensorboard_binary_path
INFO: which tensorboard: b'/home/nikola/opt/anaconda3/envs/gen/bin/tensorboard\n'

--- check: addrinfos
socket.has_ipv6 = True
socket.AF_UNSPEC = <AddressFamily.AF_UNSPEC: 0>
socket.SOCK_STREAM = <SocketKind.SOCK_STREAM: 1>
socket.AI_ADDRCONFIG = <AddressInfo.AI_ADDRCONFIG: 32>
socket.AI_PASSIVE = <AddressInfo.AI_PASSIVE: 1>
Loopback flags: <AddressInfo.AI_ADDRCONFIG: 32>
Loopback infos: [(<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('::1', 0, 0, 0)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('127.0.0.1', 0))]
Wildcard flags: <AddressInfo.AI_PASSIVE: 1>
Wildcard infos: [(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('0.0.0.0', 0)), (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('::', 0, 0, 0))]

--- check: readable_fqdn
INFO: socket.getfqdn(): 'rack2'

--- check: stat_tensorboardinfo
INFO: directory: /tmp/.tensorboard-info
INFO: .tensorboard-info directory does not exist

--- check: source_trees_without_genfiles
INFO: tensorboard_roots (1): ['/home/nikola/opt/anaconda3/envs/gen/lib/python3.6/site-packages']; bad_roots (0): []

--- check: full_pip_freeze
INFO: pip freeze --all:
absl-py==0.15.0
altair==4.1.0
AmberUtils==21.0
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
astunparse==1.6.3
async-generator==1.10
attrs==22.2.0
backcall==0.2.0
backports.zoneinfo==0.2.1
bleach==4.1.0
blinker==1.5
cached-property==1.5.2
cachetools==4.2.4
certifi==2024.8.30
cffi==1.15.1
charset-normalizer==2.0.12
click==8.0.4
comm==0.1.4
commonmark==0.9.1
cycler==0.11.0
dataclasses @ file:///home/conda/feedstock_root/build_artifacts/dataclasses_1628958435052/work
decorator==4.4.2
defusedxml==0.7.1
Deprecated==1.2.14
edgembar==0.2
entrypoints==0.4
flatbuffers==1.12
gast==0.4.0
gitdb==4.0.9
GitPython==3.1.18
google-auth==2.22.0
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.34.1
h5py==3.1.0
htmd==0.0.0
humanize==3.14.0
idna==3.10
importlib-metadata==4.8.3
importlib-resources==5.4.0
ipykernel==5.5.6
ipython==7.16.3
ipython-genutils==0.2.0
ipywidgets==7.8.4
jedi==0.17.2
Jinja2==3.0.3
joblib==1.1.1
jsonschema==3.2.0
jupyter-client==7.1.2
jupyter-core==4.9.2
jupyterlab-pygments==0.1.2
jupyterlab_widgets==1.1.10
Keras==2.2.2
Keras-Applications==1.0.4
keras-nightly==2.5.0.dev2021032900
Keras-Preprocessing==1.0.2
kiwisolver==1.3.1
llvmlite==0.36.0
Markdown==3.3.7
MarkupSafe==2.0.1
matplotlib==3.3.4
mistune==0.8.4
MMPBSA.py==16.0
moleculekit==0.6.7
mpi4py==3.1.4
nbclient==0.5.9
nbconvert==6.0.7
nbformat==5.1.3
ndfes==1.8
nest-asyncio==1.6.0
networkx==2.5.1
nibabel==3.2.2
notebook==6.4.10
numba==0.53.1
numpy @ file:///home/conda/feedstock_root/build_artifacts/numpy_1626681920064/work
oauthlib==3.2.2
olefile @ file:///home/conda/feedstock_root/build_artifacts/olefile_1602866521163/work
opt-einsum==3.3.0
packaging==21.3
packmol-memgen==2023.8.8
pandas==1.1.5
pandocfilters==1.5.1
ParmEd==4.0.0
parso==0.7.1
pdb4amber==22.0
pexpect==4.9.0
pickleshare==0.7.5
Pillow==8.4.0
pip==21.3.1
prometheus-client==0.17.1
prompt-toolkit==3.0.36
protobuf==4.21.0
ptyprocess==0.7.0
pyarrow==6.0.1
pyasn1==0.5.1
pyasn1-modules==0.3.0
pycairo==1.20.1
pycparser==2.21
pydeck==0.6.2
Pygments==2.14.0
Pympler==1.1
pyMSMT==22.0
pyparsing==3.1.4
pyrsistent==0.18.0
python-dateutil==2.9.0.post0
pytraj==2.0.6
pytz==2024.2
pytz-deprecation-shim==0.1.0.post0
PyYAML==6.0.1
pyzmq==25.1.2
requests==2.27.1
requests-oauthlib==2.0.0
rich==12.6.0
rsa==4.9
sander==22.0
scipy==1.5.4
semver==2.13.0
Send2Trash==1.8.3
setuptools==58.0.4
SimpleITK==2.1.1.2
six @ file:///home/conda/feedstock_root/build_artifacts/six_1620240208055/work
smmap==5.0.0
streamlit==1.10.0
tensorboard==2.10.1
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorboardX==2.6.2.2
tensorflow-estimator==2.5.0
tensorflow-gpu==2.5.0
termcolor==1.1.0
terminado==0.12.1
testpath==0.6.0
toml==0.10.2
toolz==0.12.0
torch==1.7.1
torchaudio==0.7.0a0+a853dff
torchio==0.18.76
torchvision==0.8.2
tornado==6.1
tqdm==4.64.1
traitlets==4.3.3
typing_extensions==4.1.1
tzdata==2024.2
tzlocal==4.2
urllib3==1.26.20
validators==0.20.0
watchdog==2.3.1
wcwidth==0.2.13
webencodings==0.5.1
Werkzeug==2.0.3
wheel==0.37.1
widgetsnbextension==3.6.9
wrapt==1.12.1
zipp==3.6.0

Here is my script which I ran import torch import torch.nn as nn from torch.autograd import Variable import time as t import matplotlib.pyplot as plt import sys plt.switch_backend('agg') sys.path.append('/home/nikola/Desktop/tik/GENiPPI/gPPMol/models_3d') import os from torchvision import utils from tensorboard_logger import Logger from tqdm import tqdm import numpy as np SAVE_PER_TIMES = 1000 from torch.nn.utils.rnn import pack_padded_sequence,pad_packed_sequence

class Generator(torch.nn.Module): def init(self, channels,is_cuda): super().init()

Filters [1024, 512, 256]

    # Input_dim = 100
    # Output_dim = C (number of channels)
    self.use_cuda = is_cuda
    self.main_module = nn.Sequential(
        # Z latent vector 100
        nn.ConvTranspose3d(in_channels=10, out_channels=1024, kernel_size=4, stride=1, padding=0),
        nn.BatchNorm3d(num_features=1024),
        nn.ReLU(True),

        # State (1024x4x4)
        nn.ConvTranspose3d(in_channels=1024, out_channels=512, kernel_size=4, stride=2, padding=1),
        nn.BatchNorm3d(num_features=512),
        nn.ReLU(True),

        # State (512x8x8)
        nn.ConvTranspose3d(in_channels=512, out_channels=256, kernel_size=4, stride=2, padding=1),
        nn.BatchNorm3d(num_features=256),
        nn.ReLU(True),

        # State (256x16x16)
        nn.ConvTranspose3d(in_channels=256, out_channels=channels, kernel_size=8, stride=1, padding=0))
        # output of main module --> Image (Cx32x32)

    self.output = nn.Tanh()

def forward(self, x,c2,only_y):
    c2 = c2.view(c2.shape[0],4,4,4)
    c2_condition_f = []
    c2_negative_f = np.zeros(c2.shape, dtype=np.float32)
    c2_negative_f = torch.Tensor(c2_negative_f)

    if self.use_cuda:
        c2_negative_f = Variable(c2_negative_f.cuda())
        c2 = Variable(c2.cuda())
    else:
        c2_negative_f = Variable(c2_negative_f)
        c2 = Variable(c2)

    for i in range(len(only_y)):
        if only_y[i] == 0:
            c2_condition_f.append(c2_negative_f)
        elif only_y[i] == 1:
            c2_condition_f.append(c2)

    c2_condition = torch.stack(c2_condition_f, 0) #16 1 4 4 4 

    if c2_condition.shape[0]!=x.shape[0]:
        print("batch_size error",c2_condition.shape,x.shape)
    try:
        cat_h3 = torch.cat([x, c2_condition], dim=1) #16 10 4 4 4
    except:
        print(c2_condition.shape,x.shape,len(only_y))  #torch.Size([7, 1, 4, 4, 4]) torch.Size([8, 9, 4, 4, 4]) 7

    cat_h3 = self.main_module(cat_h3)
    return self.output(cat_h3)

class Discriminator(torch.nn.Module): def init(self, channels): super().init()

Filters [256, 512, 1024]

    # Input_dim = channels (Cx64x64)
    # Output_dim = 1
    self.main_module = nn.Sequential(
        # Image (Cx32x32)
        nn.Conv3d(in_channels=channels, out_channels=256, kernel_size=4, stride=2, padding=1),
        nn.BatchNorm3d(num_features=256),
        nn.LeakyReLU(0.2, inplace=True),

        # State (256x16x16)
        nn.Conv3d(in_channels=256, out_channels=512, kernel_size=4, stride=2, padding=1),
        nn.BatchNorm3d(num_features=512),
        nn.LeakyReLU(0.2, inplace=True),

        # State (512x8x8)
        nn.Conv3d(in_channels=512, out_channels=1024, kernel_size=4, stride=2, padding=1),
        nn.BatchNorm3d(num_features=1024),
        nn.LeakyReLU(0.2, inplace=True))
        # output of main module --> State (1024x4x4)

    self.output = nn.Sequential(
        # The output of D is no longer a probability, we do not apply sigmoid at the output of D.
        nn.Conv3d(in_channels=1024, out_channels=1, kernel_size=4, stride=1, padding=0))

def forward(self, x):
    x = self.main_module(x)
    return self.output(x)

def feature_extraction(self, x):
    # Use discriminator for feature extraction then flatten to vector of 16384
    x = self.main_module(x)
    return x.view(-1, 1024*4*4*4)

class WGAN_CP(object): def init(self, channels,is_cuda,generator_iters,gnn_interface_model,encoder,decoder,device,batch_size=64): print("WGAN_CP init model.") self.G = Generator(channels,is_cuda) self.D = Discriminator(channels) self.gnn_interface_model = gnn_interface_model self.encoder = encoder self.decoder = decoder self.device = device self.C = channels

    # check if cuda is available
    self.check_cuda(is_cuda)

    # WGAN values from paper
    self.learning_rate = 0.00005

    self.batch_size = batch_size
    self.weight_cliping_limit = 0.01

    # WGAN with gradient clipping uses RMSprop instead of ADAM
    self.d_optimizer = torch.optim.RMSprop(self.D.parameters(), lr=self.learning_rate)
    self.g_optimizer = torch.optim.RMSprop(list(self.G.parameters()) + list(self.gnn_interface_model.parameters()), 
        lr=self.learning_rate)

    # Set the logger
    self.logger = Logger('./logs')
    self.logger.writer.flush()
    self.number_of_images = 10

    self.generator_iters = generator_iters
    self.critic_iter = 30

def get_torch_variable(self, arg):
    if self.cuda:
        return Variable(arg).cuda(self.cuda_index)
    else:
        return Variable(arg)

def check_cuda(self, cuda_flag=False):
    if cuda_flag:
        self.cuda_index = 0
        self.cuda = True
        self.D.cuda(self.cuda_index)
        self.G.cuda(self.cuda_index)
        print("Cuda enabled flag: {}".format(self.cuda))
    else:
        self.cuda = False

and I got this error AttributeError: 'Logger' object has no attribute 'writer'

arcra commented 3 weeks ago

I haven't looked very deeply into this, but it looks like you're using a very old version of tensorflow.

https://pypi.org/project/tensorflow-gpu/ mentions "tensorflow-gpu has been removed. Please install tensorflow instead."

The latest published version of TF is 2.17.0: https://pypi.org/project/tensorflow/, and 2.18.0 should be available soon.