Why HF_TASKS_AUTO not recognized from fastai? - tokenize

This is PIP install that I did
!pip install ohmeow-blurr==0.0.6
!pip install datasets==1.3.0 -qq
!pip install fsspec==2021.7.0
This is the library imports that I did
import ast
import torch
from fastai.text.all import *
from transformers import *
from blurr.data.all import *
from blurr.modeling.all import *
I tried using fastai2 but this is the error that I get
RuntimeError Traceback (most recent call last)
Input In [16], in <cell line: 3>()
1 import ast
2 import torch
----> 3 from fastai2.text.all import *
4 from transformers import *
8 from blurr.data.all import *
File ~\anaconda3\lib\site-packages\fastai2\text\all.py:1, in <module>
----> 1 from ..basics import *
2 from ..callback.all import *
3 from .core import *
File ~\anaconda3\lib\site-packages\fastai2\basics.py:1, in <module>
----> 1 from .data.all import *
2 from .optimizer import *
3 from .callback.core import *
File ~\anaconda3\lib\site-packages\fastai2\data\all.py:1, in <module>
----> 1 from ..torch_basics import *
2 from .core import *
3 from .load import *
File ~\anaconda3\lib\site-packages\fastai2\torch_basics.py:4, in <module>
2 from .imports import *
3 from .torch_imports import *
----> 4 from .torch_core import *
5 from .layers import *
File ~\anaconda3\lib\site-packages\fastai2\torch_core.py:312, in <module>
309 if isinstance(f, (MethodWrapperType, BuiltinFunctionType, BuiltinMethodType, MethodType, FunctionType)):
310 setattr(TensorBase, fn, get_f(fn))
--> 312 _patch_tb()
314 # Cell
315 class TensorCategory(TensorBase): pass
File ~\anaconda3\lib\site-packages\fastai2\torch_core.py:308, in _patch_tb()
306 for fn in dir(t):
307 if fn in skips: continue
--> 308 f = getattr(t, fn)
309 if isinstance(f, (MethodWrapperType, BuiltinFunctionType, BuiltinMethodType, MethodType, FunctionType)):
310 setattr(TensorBase, fn, get_f(fn))
RuntimeError: tensor.H is only supported on matrices (2-D tensors). Got 1-D tensor.
This is the task that I wanted to add but somehow not being able to
task = HF_TASKS_AUTO.TokenClassification
This the error that I get from the code above

The API had to be updated to work on kaggle ... you should be able to simply use get_hf_objects from the utils module ...
from blurr.text.utils import get_hf_objects
hf_arch, hf_config, hf_tokenizer, hf_model = get_hf_objects(
"microsoft/deberta-v3-small",
model_cls=AutoModelForSequenceClassification
)

Related

"im2col_out_cpu" not implemented for 'Byte'

I am trying to generate overlap patches from image size (112,112) but i am unable to do so. I have already tried a lot but it didn't work out.
**Code**
import torch
import numpy as np
import torch.nn as nn
from torch import nn
from PIL import Image
import cv2
import os
import math
import torch.nn.functional as F
import torchvision.transforms as T
from timm import create_model
from typing import List
import matplotlib.pyplot as plt
from torchvision import io, transforms
from utils_torch import Image, ImageDraw
from torchvision.transforms.functional import to_pil_image
IMG_SIZE = 112
# PATCH_SIZE = 64
resize = transforms.Resize((IMG_SIZE, IMG_SIZE))
img = resize(io.read_image("Adam_Brody_233.png"))
img = img.to(torch.float32)
image_size = 112
patch_size = 28
ac_patch_size = 12
pad = 4
img = img.unsqueeze(0)
soft_split = nn.Unfold(kernel_size=(ac_patch_size, ac_patch_size), stride=(patch_size, patch_size), padding=(pad, pad))
patches = soft_split(img).transpose(1, 2)
fig, ax = plt.subplots(16, 16)
for i in range(16):
for j in range(16):
sub_img = patches[:, i, j]
ax[i][j].imshow(to_pil_image(sub_img))
ax[i][j].axis('off')
plt.show()
Traceback
Traceback (most recent call last):
File "/home/cvpr/Documents/OPVT/unfold_ours.py", line 32, in <module>
patches = soft_split(img).transpose(1, 2)
File "/home/cvpr/anaconda3/envs/OPVT/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cvpr/anaconda3/envs/OPVT/lib/python3.7/site-packages/torch/nn/modules/fold.py", line 295, in forward
self.padding, self.stride)
File "/home/cvpr/anaconda3/envs/OPVT/lib/python3.7/site-packages/torch/nn/functional.py", line 3831, in unfold
_pair(dilation), _pair(padding), _pair(stride))
RuntimeError: "im2col_out_cpu" not implemented for 'Byte'
Yes this is an open issue in PyTorch. A simple fix is just to convert your image tensor from ints to floats you can do it like this:
img = img.to(torch.float32)
This should solve your problem

import pandas error : Traceback (most recent call last) and expected string or bytes-like object

I installed GIS-Pro and use Jupyter. I believe Jupyter is in the GIS-Pro package. I use Jupyter to write Python codes. Since yesterday, I've got the following errors once executing import pandas as pd :
TypeError Traceback (most recent call last)
C:\Users\AppData\Local\Temp\2/ipykernel_23172/4080736814.py in <module>
----> 1 import pandas as pd
C:\ArcGISPro28\bin\Python\envs\arcgispro-py3\lib\site-packages\pandas\__init__.py in <module>
# numpy compat
from pandas.compat import (
np_version_under1p18 as _np_version_under1p18,
is_numpy_dev as _is_numpy_dev,
C:\ArcGISPro28\bin\Python\envs\arcgispro-py3\lib\site-packages\pandas\compat\__init__.py in <module>
np_version_under1p20)
from pandas.compat.pyarrow import (
pa_version_under1p0,
pa_version_under2p0,
C:\ArcGISPro28\bin\Python\envs\arcgispro-py3\lib\site-packages\pandas\compat\pyarrow.py in <module>
pa_version = pa.__version__
palv = Version(_pa_version)
pa_version_under1p0 = _palv < Version("1.0.0")
pa_version_under2p0 = _palv < Version("2.0.0")
C:\ArcGISPro28\bin\Python\envs\arcgispro-py3\lib\site-packages\pandas\util\version\__init__.py in __init__(self, version)
# Validate the version and parse it into pieces
match = self._regex.search(version)
if not match:
raise InvalidVersion(f"Invalid version: '{version}'")
TypeError: expected string or bytes-like object

AttributeError: module 'torch.jit' has no attribute '_script_if_tracing'

import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()
# import some common libraries
import numpy as np
import cv2
import random
from google.colab.patches import cv2_imshow
import matplotlib.pyplot as plt
# import some common detectron2 utilities
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog
AttributeError Traceback (most recent call last)
<ipython-input-3-fa7489d52c2b> in <module>()
12 # import some common detectron2 utilities
13
---> 14 from detectron2.engine import DefaultPredictor
15 from detectron2.config import get_cfg
16 from detectron2.utils.visualizer import Visualizer
15 frames
/usr/local/lib/python3.6/dist-packages/torchvision/ops/boxes.py in <module>()
43
44
---> 45 #torch.jit._script_if_tracing
46 def batched_nms(
47 boxes: Tensor,
AttributeError: module 'torch.jit' has no attribute '_script_if_tracing'
In my case using pip install torchvision==0.7.0 instead of torchvision==0.7.0+cpu solved the error.

Creating command lines with python (argparse)

I want to create a command line with python (argparse). The goal is to import a dataframe and then print its 5 first rows, however, when I run the command, this error shows up :
File "try.py", line 3, in <module>
import pandas as pd
File "C:\Users\szouaoui\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\__init__.py", line 17, in <module>
"Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
ImportError: Unable to import required dependencies:
numpy: DLL load failed: Le module spécifié est introuvable.
it seems that the program is unable to import the pandas library
here is the code:
import argparse
import sys
import pandas as pd
my_parser = argparse.ArgumentParser(description='Unconstraining demand for specified dates, shops and categories/n')
my_parser.add_argument("path",type=str, action="store")
my_args = my_parser.parse_args()
input_file = sys.argv[1]
data = pd.read_csv(input_file)
print(data.head())
command line :
python try.py /path_to_file/dataframe_name.csv

ImportError: No module named 'svmutil'

i get stuck right now, my code:
import sys
import os
import itertools
import random
from PIL import Image
from svmutil import *
DIMENSION = 200
ROOT_DIR = "../train/"
NEGATIVE = "negative"
POSITIVE = "positive"
CLASSES = [NEGATIVE, POSITIVE]
....
and it says :
ImportError: No module named 'svmutil'
now I use python 3.5
What should I do now?