[Part 2] I tried to solve the error "User Warning: An input could not be retrieved. It could be because a worker has died" that occurred in Mask R-CNN.

Until the cause of the error is identified

[[Part 1] I tried to solve the error "User Warning: An input could not be retrieved. It could be because a worker has died" that occurred in Mask R-CNN. ] (https://qiita.com/skperfarming/items/68cdec8ad8672837bd38)

In the first part, we explored the occurrence of errors and their causes. In the second part, I will introduce an implementation that you can actually learn properly.

DOWNLOAD/SETUP/IMPORT

nucleus_train.py


# Mount drive
from google.colab import drive
drive.mount('/content/drive/')
%tensorflow_version 1.x

Mount google drive. Specify the previous version of tensorflow as well.

nucleus_train.py


# Change directory to project folder
%cd "/content/drive/My Drive/DeepLearning2/Mask_RCNN"
!python setup.py install

Specify the directory where setup.py is located and set up.

nucleus_train.py


import os
import sys
import random
import math
import re
import time
import numpy as np
import tensorflow as tf
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.patches as patches

# Root directory of the project
ROOT_DIR = os.path.abspath("../../")

# Import Mask RCNN
sys.path.append(ROOT_DIR)  # To find local version of the library
from mrcnn import utils
from mrcnn import visualize
from mrcnn.visualize import display_images
import mrcnn.model as modellib
from mrcnn.model import log

from samples.nucleus import nucleus

%matplotlib inline 

# Directory to save logs and trained model
LOGS_DIR = os.path.join(ROOT_DIR, "logs")

I will import various familiar things. Maybe I just copied the other ipynb stuff.

Until learning

nucleus_train.py


!mkdir "/content/datasets"
!cp "/content/drive/My Drive/DeepLearning2/Mask_RCNN/datasets/nucleus/stage1_train.zip" "/content/datasets"
!mkdir "/content/datasets/stage1_train"
!unzip /content/datasets/stage1_train.zip -d /content/datasets/stage1_train

Create a folder called datasets directly under content → Store zip in it → Create a folder to put the decompressed data directly under datasets → Unzip the zip and store it in the created folder

nucleus_train.py


%cd "/content/drive/My Drive/DeepLearning2/Mask_RCNN/samples/nucleus/"
!python3 nucleus.py train --dataset=/content/datasets/ --subset=train --weights="/content/drive/My Drive/DeepLearning2/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5"

Move directory to where Nucleus.py is → Execute the command to start learning!

Error resolution

I was able to proceed to Epoch 40 without the error mentioned in the first part. If the session expires in the middle, you can resume learning from the middle by specifying as follows.

nucleus_train.py


!python3 nucleus.py train --dataset=/content/datasets/ --subset=train --weights=last

I was able to proceed with learning safely! Please comment if there are any improvements ~

Recommended Posts

[Part 1] I tried to solve the error "User Warning: An input could not be retrieved. It could be because a worker has died" that occurred in Mask R-CNN.
[Part 2] I tried to solve the error "User Warning: An input could not be retrieved. It could be because a worker has died" that occurred in Mask R-CNN.
I thought it would be slow to use a for statement in NumPy, but that wasn't the case.
What seems to be a template of the standard input part of the competition pro in python3