enhance reader (#628)
parent
a02a927139
commit
bba176e05a
|
@ -70,6 +70,12 @@ int main(int argc, char **argv) {
|
|||
for (int idx = 0; idx < img_files_list.size(); ++idx) {
|
||||
std::string img_path = img_files_list[idx];
|
||||
cv::Mat srcimg = cv::imread(img_path, cv::IMREAD_COLOR);
|
||||
if (!srcimg.data) {
|
||||
std::cerr << "[ERROR] image read failed! image path: " << img_path
|
||||
<< "\n";
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
cv::cvtColor(srcimg, srcimg, cv::COLOR_BGR2RGB);
|
||||
|
||||
double run_time = classifier.Run(srcimg);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
import numpy as np
|
||||
import random
|
||||
import imghdr
|
||||
import os
|
||||
import signal
|
||||
|
@ -182,12 +183,17 @@ class CommonDataset(Dataset):
|
|||
return
|
||||
|
||||
def __getitem__(self, idx):
|
||||
line = self.full_lines[idx]
|
||||
img_path, label = line.split(self.delimiter)
|
||||
img_path = os.path.join(self.params['data_dir'], img_path)
|
||||
with open(img_path, 'rb') as f:
|
||||
img = f.read()
|
||||
return (transform(img, self.ops), int(label))
|
||||
try:
|
||||
line = self.full_lines[idx]
|
||||
img_path, label = line.split(self.delimiter)
|
||||
img_path = os.path.join(self.params['data_dir'], img_path)
|
||||
with open(img_path, 'rb') as f:
|
||||
img = f.read()
|
||||
return (transform(img, self.ops), int(label))
|
||||
except Exception as e:
|
||||
logger.error("data read faild: {}, exception info: {}".format(line,
|
||||
e))
|
||||
return self.__getitem__(random.randint(0, len(self)))
|
||||
|
||||
def __len__(self):
|
||||
return self.num_samples
|
||||
|
|
Loading…
Reference in New Issue