How can I solve this problem in vs code, ipython (tensorflow)? - python-3.x

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import check_util.checker as checker
from IPython.display import clear_output
from PIL import Image
import os
import time
import re
from glob import glob
import shutil
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow import keras
print('tensorflow version: {}'.format(tf.__version__))
print('GPU available: {}'.format(tf.test.is_gpu_available()))
When I run this, there is no error. But it shows as indefinitely in progress.
(Current 630..631..632...sec)

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

how to import the libraries of toimage in scipy.misc?

import matplotlib.pyplot as plt
import cv2
from scipy.misc import toimage
im = toimage(skeleton)
cv2.imwrite('./zee/img'+(str(count)+".png"),im)
but we get
ImportError: cannot import name 'toimage'

tensorflow 2.0, tfds.load 'utf-8' codec error

Imports & Settings
%matplotlib inline
from pathlib import Path
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
import seaborn as sns
import tensorflow as tf
from tensorflow.keras.applications.densenet import DenseNet201
from tensorflow.keras.layers import Dense, BatchNormalization
from tensorflow.keras.models import Sequential
from tensorflow.keras.callbacks import ModelCheckpoint, EarlyStopping
from tensorflow.keras.regularizers import l1_l2
from tensorflow.keras.optimizers import Adam
import tensorflow_datasets as tfds
Load EuroSat Dataset
(raw_train, raw_validation), metadata = tfds.load('eurosat',
split=['train[:90%]','train[90%:]'],
with_info=True,
shuffle_files=False,
as_supervised=True,
data_dir='../data/tensorflow')
i got error message
how can i fix it?
i use tensorflow2
I guess there's a problem with the codec.

KNeighborsClassifier from sklearn.neighbors import error

guys am having import error while trying to import KNeighborsClassifier from sklearn.neighbors import k
its showing the following errors
ImportError: cannot import name 'kNeighborsClassifier' from 'sklearn.neighbors' (/home/themysteriouschemeng/anaconda3/lib/python3.7/site-packages/sklearn/neighbors/init.py)
You have used small k instead of capital K in KNeighborsClassifier.
Your import -from sklearn.neighbors import kNeighborsClassifier
Right import - from sklearn.neighbors import KNeighborsClassifier
Replace small k with capital K in KNeighborsClassifier and this will fix your import issue.
Can you add the code you are using?
Btw the basic code to import is
from sklearn.neighbors import KNeighborsClassifier
model = KNeighborsClassifier(n_neighbors=4)

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

Resources