쫑쫑JJONG
끄적끄적 오후5시37분
쫑쫑JJONG
전체 방문자
오늘
어제
  • 분류 전체보기 (198)
    • Paper Reading (5)
    • Math (5)
    • Data Science (13)
      • SQL (12)
      • Data Analyst (1)
    • AI Track (32)
      • CV (21)
      • CV Remind (2)
      • NLP (1)
      • AI Basic (8)
    • Python (1)
      • Basic (8)
      • Application (5)
    • Robotics (31)
      • ROS (15)
      • Collabot_proj (16)
    • NaverBoost Camp 4기 (45)
      • 부스트일지 (13)
      • [P stage] Image Classificat.. (4)
      • [P stage] Object Detection (12)
      • [P stage] Semantic Segmenta.. (6)
      • [P stage] Final Project (5)
      • CV (1)
      • DL BASIC (4)
    • Excel (1)
    • Git (8)
      • Git (8)
    • Network (3)
      • 통신 (3)
    • 코테준비 (14)
      • Programmers (11)
      • 기타 (3)
    • 환경설정 (19)
    • etc (7)
      • 활동 (2)
      • TIP (3)
      • 잡동사니 (2)
    • 금융관련 (0)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • 포트폴리오

인기 글

태그

  • SQL
  • GIT
  • CV
  • Monte Carlo Sampling
  • diffusion
  • N
  • Confusion Matrix
  • 이고잉
  • error
  • Data Scraping
  • 논문분석
  • mmdetection
  • NLP
  • Arduino
  • collabot
  • transformer
  • ros
  • python
  • segmentation
  • 환경설정
  • robotics

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
쫑쫑JJONG

끄적끄적 오후5시37분

Python/Application

[Data Scraping] Error : Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

2023. 2. 10. 15:00
728x90

Error 내용

 

Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

 

-> data는 다음과 같이

use_cuda = torch.cuda.is_available()
device = torch.device("cuda" if use_cuda else "cpu")

image = np.array(cv2.imread('./sample_data/Black_porgy.JPG'))
image = transform(image=image)['image']
image = image.unsqueeze(0)
image = image.to(device, dtype=torch.float32)

device 즉, cuda에 올렸지만 model은 cuda에 올리지 않아서 발생한 문제

 

기존 코드

class TempModel(nn.Module):
    def __init__(self, num_classes):
        super().__init__()
        self.efficientnet = timm.create_model('efficientnet_b4', pretrained = True, num_classes = num_classes, drop_rate=0.5, act_layer = nn.ReLU)

    def forward(self, x):
        x = self.efficientnet(x)
        return x

file_path = './fish_EfficientNetB4_best_epoch23_0.7847.pth'

model = TempModel(num_classes =12)
model.load_state_dict(torch.load(file_path))
model.eval()

이걸 device에 올려주도록 하자

 

 

728x90
저작자표시 비영리 변경금지 (새창열림)

'Python > Application' 카테고리의 다른 글

[Python] Streamlit 활용 전 정리  (0) 2024.06.05
[Data Scraping] 구글에서 고화질 이미지 스크래핑(크롤링) - selenium  (0) 2023.01.27
[Scraping] Web Crowling 이라기 보단 Scraping (beautifulsoup4)  (0) 2023.01.24
[Scraping] HTML, XPath, Requests,정규식 찍먹해보기 (+User-agent)  (1) 2023.01.19
    'Python/Application' 카테고리의 다른 글
    • [Python] Streamlit 활용 전 정리
    • [Data Scraping] 구글에서 고화질 이미지 스크래핑(크롤링) - selenium
    • [Scraping] Web Crowling 이라기 보단 Scraping (beautifulsoup4)
    • [Scraping] HTML, XPath, Requests,정규식 찍먹해보기 (+User-agent)
    쫑쫑JJONG
    쫑쫑JJONG
    connect : tmdwhd619@naver.com

    티스토리툴바