导入fastbook时会出现各种错误,更具体地说是torch

2024-09-27 00:18:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个项目,但我遇到了一个无法识别的错误。欢迎任何帮助

代码:

try:
  import fastbook
  fastbook.setup_book()
except:
  !pip install -Uqq fastbook
  import fastbook
  fastbook.setup_book()

try:
  learn_inf = load_learner(path/'export.pkl')
except:
  from fastbook import *
  from fastai.vision.widgets import *

  path = Path('/content/gdrive/My Drive/Datasets/HornetImages')
  path2 = Path('/content/gdrive/My Drive/Datasets/HornetImages/Hornet (1).jpg')

  path.ls
  from PIL import Image
  img = Image.open(path2)
  print(img.shape)
  img.to_thumb(128,128)

  def is_hornet(x): return x[0].isupper()

  item_tfms=Resize(128, ResizeMethod.Squish)
  item_tfms=Resize(128, ResizeMethod.Pad, pad_mode='zeros')
  item_tfms=RandomResizedCrop(128, min_scale=0.3)# - 30% of the image area is zoomed by specifying 0.3

  tfms = aug_transforms(do_flip = True, flip_vert = False, mult=2.0)

  data= ImageDataLoaders.from_folder(path,train = "train", valid_pct=0.2, item_tfms=Resize(128),         batch_tfms=tfms, bs = 30, num_workers = 4)

  Data = DataBlock( blocks=(ImageBlock, CategoryBlock), get_items=get_image_files, 
  splitter=RandomSplitter(valid_pct=0.2, seed=42), get_y=parent_label, item_tfms=Resize(128))
  dls = Data.dataloaders(path)

  learn = cnn_learner(data, resnet50, metrics=error_rate)
  learn.fine_tune(4)

  interp = ClassificationInterpretation.from_learner(learn)
  interp.plot_confusion_matrix()

  from fastai.vision.widgets import *
  cleaner = ImageClassifierCleaner(learn)
  cleaner
  learn.export()


!pip3 install --upgrade opencv-python

import cv2

cam = cv2.VideoCapture(0)

frame = cam.read()

learn_inf = load_learner(path/'export.pkl')

learn_inf.predict(str(input("Enter the file path. Example;\nC:\\Users\MYUSERNAME\\Pictures\\CameraRoll\nEnter yours here: ")))

错误:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 0: invalid start byte

但是,错误变为

'utf-8' codec can't decode byte 0xa0 in position 0: invalid start byte
ValueError: module functions cannot set METH_CLASS or METH_STATIC

及其他

操作系统:Windows 10

Jupyter笔记本服务器:Google Colab(本地运行时)和Jupyter notebookconda virtual enviornment

谢谢, 喹尼泊10


Tags: pathfromimportimgget错误exportbyte

热门问题