Run TensorBoard on Colab - pytorch

I have following code
!pip install timm
import timm
from torchsummary import summary
import torchvision.models as models
import torch
import os
from torch.utils.tensorboard import SummaryWriter
%load_ext tensorboard
#model = models.inception_v3(pretrained=False)
model = timm.create_model('inception_v4', pretrained=False)
#model.cuda()
summary(model, (3, 440, 440))
writer=SummaryWriter('/content/logsdir')
%tensorboard --logdir /content/logsdir
When the code is run, there is error as No graph definition files were found. What could be wrong?

Use Built-in magic commands https://ipython.readthedocs.io/en/stable/interactive/magics.html
Read reference document at https://colab.research.google.com/github/tensorflow/tensorboard/blob/master/docs/tensorboard_in_notebooks.ipynb

Related

ImportError: cannot import name 'int_classes' from 'torch._six' (/usr/local/lib/python3.7/dist-packages/torch/_six.py)

I am working on healthcare image dataset for image segmentation. More specific, it is "Spinal Cord Gray Matter Segmentation Using PyTorch". When I am trying to install libraries initially using this code:
!pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.0-cp36-cp36m-linux_x86_64.whl
!pip3 install torchvision
!pip install medicaltorch
!pip3 install numpy==1.14.1
it is showing some errors in between required satisfied like this:
1st screenshot
2nd screenshot
After that I am importing libraries:
from collections import defaultdict
import time
import os
import numpy as np
from tqdm import tqdm
from medicaltorch import datasets as mt_datasets
from medicaltorch import models as mt_models
from medicaltorch import transforms as mt_transforms
from medicaltorch import losses as mt_losses
from medicaltorch import metrics as mt_metrics
from medicaltorch import filters as mt_filters
import torch
from torchvision import transforms
from torch.utils.data import DataLoader
from torch import autograd, optim
import torch.backends.cudnn as cudnn
import torch.nn as nn
import torchvision.utils as vutils
cudnn.benchmark = True
import matplotlib.pyplot as plt
%matplotlib inline
This importing is throwing an error like this:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-8-80b8c583d1fe> in <module>()
20
21
---> 22 from medicaltorch import datasets as mt_datasets
23 from medicaltorch import models as mt_models
24 from medicaltorch import transforms as mt_transforms
/usr/local/lib/python3.7/dist-packages/medicaltorch/datasets.py in <module>()
11 from torch.utils.data import Dataset
12 import torch
---> 13 from torch._six import string_classes, int_classes
14
15 from PIL import Image
ImportError: cannot import name 'int_classes' from 'torch._six' (/usr/local/lib/python3.7/dist-packages/torch/_six.py)
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
can someone help me resolve this?
In pytorch 1.9 int_classes variable in torch._six was removed. facebookresearch/TimeSformer#47
Use this code instead.
from torch._six import string_classes
int_classes = (bool, int)
See source here: https://github.com/visionml/pytracking/issues/272

Importing sklearn module in pyscript

how to import modules which are in form of
"from sklearn.tree import DecisionTreeRegressor" in Pyscript?
The way you import modules works as follows:
Include the relevant package in the environment
<py-env>
- scikit-learn
</py-env>
Import the module as you would do it in any other python file
<py-script>
from sklearn.tree import DecisionTreeClassifier
dt = DecisionTreeClassifier()
...
</py-script>

Tensorflow Lite Model Maker error: object has no attribute 'index_to_label'

I'm usign Tensorflow Lite Model Maker to adapt a model to citrus_leaves dataset, but following the documentation I get this error:
AttributeError: 'PrefetchDataset' object has no attribute
'index_to_label'
I'm making this code on Google colab:
!pip install -q tflite-model-maker
!pip install tensorflow-datasets
!pip install tfds-nightly
import os
import numpy as np
import tensorflow as tf
assert tf.__version__.startswith('2')
from tflite_model_maker import model_spec
from tflite_model_maker import image_classifier
from tflite_model_maker.config import ExportFormat
from tflite_model_maker.config import QuantizationConfig
from tflite_model_maker.image_classifier import DataLoader
import tensorflow_datasets as tfds
import matplotlib.pyplot as plt
(test_data, train_data), info = tfds.load('citrus_leaves', split=["train[:20%]", "train[20%:]"], shuffle_files=True, with_info=True, as_supervised=True)
model = image_classifier.create(train_data) # Here the error happens
loss, accuracy = model.evaluate(test_data)
Here is the Link to dataset
and here is the link to the docs that I was following.
I have no idea why this error is happening, I would be grateful if someone could help me.
Thanks!

No OUTPUT from Jupyter Notebook. NO Error Shown

I am running a Jupyter notebook but I do not get any output or error telling me if something is wrong. I have tried installing tornado as some other threads have suggested as well as the command pip install notebook --upgrade
While I do not think there is a problem with my code here it is.
Any help is truly appreciated.
import os
import numpy as np
import pandas as pd
import cv2
from glob import glob
import tensorflow as tf
from tensorflow.keras.layers import *
from tensorflow.keras.applications import MobileNetV2
from tensorflow.keras.callbacks import ModelCheckpoint, ReduceLROnPlateau
from tensorflow.keras.optimizers import Adam
from sklearn.model_selection import train_test_split
if __name__=="_main_":
path="dog-breed-identification/"
train_path = os.path.join(path, "train/*")
train_path = os.path.join(path, "test/*")
train_path = os.path.join(path, "labels.csv")
labels_df = pd.read_csv(labels_path)
#name of column in csv
breed = labels_df["breed"].unique()
print("Number of Breed: ", len(breed))
enter code here
As it turns out, if I delete
if __name__=="_main_":
I get an output

visualizing models using plot_model tensorflow.keras

>>> from tensorflow.keras.applications import VGG16
>>> from tensorflow.keras.utils import plot_model
>>> plot_model(VGG16, to_file="vgg16.png", show_shapes=True)
AttributeError: 'function' object has no attribute '_is_graph_network'
I tried changing show_shapes=False, but the same error appears. I was able to get the program run for custom made models.
tensorflow.keras.applications.VGG16 is a function that you need to call to get a keras.Model instance. See https://www.tensorflow.org/api_docs/python/tf/keras/applications/VGG16.
Something that would work :
from tensorflow.keras.applications import VGG16
from tensorflow.keras.utils import plot_model
plot_model(VGG16())

Resources