teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

ソースコードの記法を改めました。

2021/11/26 00:27

投稿

kohyan
kohyan

スコア5

title CHANGED
File without changes
body CHANGED
@@ -3,8 +3,9 @@
3
3
  色々と調べてみましたが、分かりませんでした。
4
4
  何方か教えて頂けますでしょうか?
5
5
 
6
+
6
- ---------------------------------------------------------------------------------------------
7
+ ```python
7
- input_dir = "C://Users/hkoga/Desktop/■AI_Quest\PBL05_画像分類/④AIモデルの作成/"
8
+ nput_dir = "C://Users/・・・・・・/・・・/・・・/・・・/"
8
9
 
9
10
  train = pd.read_csv(input_dir + 'train.csv')
10
11
  test = pd.read_csv(input_dir + 'test.csv')
@@ -13,10 +14,12 @@
13
14
  train_images_path_list = sorted(glob.glob(input_dir + 'train_images/*.png'))
14
15
  train_annotations_path_list = sorted(glob.glob(input_dir + 'train_annotations/*.png'))
15
16
  test_images_path_list = sorted(glob.glob(input_dir + 'test_images/*.png'))
17
+ ```
16
18
 
17
19
 
18
20
  ここまでOKだったのですが、下記の画像のパスを指定する際に<エラー>が出てしまいます。
19
21
 
22
+ ```python
20
23
  for image_id in train_anomaly_id_list:
21
24
  print(f'\n====={image_id}=====')
22
25
 
@@ -31,18 +34,9 @@
31
34
  ax[1].imshow(annot, cmap='gray')
32
35
 
33
36
  plt.show()
37
+ ```
34
38
 
35
39
  <エラー>
36
- ```ここに言語を入力
40
+ ```python
37
- error Traceback (most recent call last)
38
- <ipython-input-25-61b53ceb14a6> in <module>
39
- 7
40
- 8 # 画像の読み込み
41
- ----> 9 image = cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB)
42
- 10 annot = cv2.imread(annot_path, 0)
43
- 11
44
-
45
41
  error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-u4kjpz2z\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
46
- '
47
- ```
42
+ ```
48
- ---------------------------------------------------------------------------------------------

2

再度、修正しました。

2021/11/26 00:27

投稿

kohyan
kohyan

スコア5

title CHANGED
File without changes
body CHANGED
@@ -20,15 +20,12 @@
20
20
  for image_id in train_anomaly_id_list:
21
21
  print(f'\n====={image_id}=====')
22
22
 
23
- # 画像のパスを指定
24
23
  image_path = os.path.join(input_dir, 'train_images', f'{image_id}.png')
25
24
  annot_path = os.path.join(input_dir, 'train_annotations', f'{image_id}.png')
26
25
 
27
- # 画像の読み込み
28
26
  image = cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB)
29
27
  annot = cv2.imread(annot_path, 0)
30
28
 
31
- # 画像の描画
32
29
  fig, ax = plt.subplots(1, 2, figsize=(10, 5), dpi=80)
33
30
  ax[0].imshow(image)
34
31
  ax[1].imshow(annot, cmap='gray')

1

ソースコードを提示し直しました。失礼しました。

2021/11/25 23:24

投稿

kohyan
kohyan

スコア5

title CHANGED
File without changes
body CHANGED
@@ -4,24 +4,48 @@
4
4
  何方か教えて頂けますでしょうか?
5
5
 
6
6
  ---------------------------------------------------------------------------------------------
7
- [絶対パス]
8
- input_dir = "C://Users/・・・/・・・/・・・/・・・/"
7
+ input_dir = "C://Users/hkoga/Desktop/■AI_Quest\PBL05_画像分類/④AIモデルの作成/"
9
-
10
- [テーブルデータの読み込み]
8
+
11
9
  train = pd.read_csv(input_dir + 'train.csv')
12
- ・・・・
10
+ test = pd.read_csv(input_dir + 'test.csv')
11
+ sub = pd.read_csv(input_dir + 'sample_submit.csv', header=None)
13
12
 
14
- [画像データのファイルパスの取得]
15
13
  train_images_path_list = sorted(glob.glob(input_dir + 'train_images/*.png'))
14
+ train_annotations_path_list = sorted(glob.glob(input_dir + 'train_annotations/*.png'))
16
- ・・・・
15
+ test_images_path_list = sorted(glob.glob(input_dir + 'test_images/*.png'))
17
16
 
18
- ここまでOKだったのですが、
19
17
 
20
- 下記の画像のパスを指定する際に<エラー>が出てしまいます。
18
+ ここまでOKだったのですが、下記の画像のパスを指定する際に<エラー>が出てしまいます。
21
- image_path = os.path.join(input_dir, 'train_images', f'{image_id}.png')
22
19
 
20
+ for image_id in train_anomaly_id_list:
21
+ print(f'\n====={image_id}=====')
22
+
23
+ # 画像のパスを指定
24
+ image_path = os.path.join(input_dir, 'train_images', f'{image_id}.png')
25
+ annot_path = os.path.join(input_dir, 'train_annotations', f'{image_id}.png')
26
+
27
+ # 画像の読み込み
28
+ image = cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB)
29
+ annot = cv2.imread(annot_path, 0)
30
+
31
+ # 画像の描画
32
+ fig, ax = plt.subplots(1, 2, figsize=(10, 5), dpi=80)
33
+ ax[0].imshow(image)
34
+ ax[1].imshow(annot, cmap='gray')
35
+
36
+ plt.show()
37
+
23
38
  <エラー>
24
39
  ```ここに言語を入力
40
+ error Traceback (most recent call last)
41
+ <ipython-input-25-61b53ceb14a6> in <module>
42
+ 7
43
+ 8 # 画像の読み込み
44
+ ----> 9 image = cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB)
45
+ 10 annot = cv2.imread(annot_path, 0)
46
+ 11
47
+
25
48
  error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-u4kjpz2z\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
49
+ '
26
50
  ```
27
51
  ---------------------------------------------------------------------------------------------