Docker: 오류 발생 [Errno 2] 해당 파일 또는 디렉터리 없음

2919 단어 python
0

Dockerfile, readme.py 및 requirements.txt를 사용하여 간단한 앱을 만들고 있습니다. Dockerfile이 빌드될 때 "No such file or directory"오류가 발생합니다. 그러나 Dockerfile에서 ADD를 COPY로 변경하면 작동합니다. 이것이 왜 그런지 아십니까? docker build 명령을 실행하는 동안 docker 파일의 마지막 줄에서 실행될 때 이 오류가 발생합니다.

import numpy as np
import base64 
from PIL import Image
import io
import cv2
import skimage
import tensorflow as tf
def preprocessor(base64image,size):

    try:
        img_bytes = base64.b64decode(base64image)
        img = Image.open(io.BytesIO(img_bytes))
        img.verify()
        img.close()
        img = Image.open(io.BytesIO(img_bytes))
        img_arr = np.asarray(img)
        if len(img_arr.shape) == 2:
            img_arr = skimage.color.gray2rgb(img_arr)      
        if len(img_arr.shape) > 2 and img_arr.shape[2] == 4:
            img_arr = cv2.cvtColor(img_arr, cv2.COLOR_BGRA2BGR)
        orig_area = img_arr.shape[0]*img_arr.shape[1]
        resize_area = size[0]*size[1]

        if orig_area < resize_area:
            img_arr = cv2.resize(img_arr, size, interpolation = cv2.INTER_LINEAR)
        elif orig_area > resize_area:
            img_arr = cv2.resize(img_arr, size, interpolation = cv2.INTER_AREA)
        img_arr = img_arr.astype('float32') / 255.0
        img_arr = np.reshape(img_arr,[1]+list(img_arr.shape))

        return img_arr

    except:

        print('****** Error during image preprocessing ******')

#############################################

import os
from keras.models import load_model,save_model
import numpy as np
import tensorflow as tf

input_img_dir = '/app/Images for testing 2'
input_img_arr = []
image_name_arr = []
count = 0

for file in os.listdir(input_img_dir):
    file = file.lower()
    if (file.endswith('jpg')) or (file.endswith('jpeg'))  or (file.endswith('png') or (file.endswith('jfif'))):

        input_img_arr.append(os.path.join(input_img_dir,file))

with tf.device('/CPU:0'):
    model = load_model('/app/Final Models/crop_ResNet152V2_model_best_at_13_0.9923.h5')
    class_labels = ['Maize', 'Grapes', 'Cotton', 'Rice']

for image_path in input_img_arr:
    binary_image = open(image_path, "rb").read()#HERE IT GIVES ERROR
    base64image = base64.b64encode(binary_image)
    img = preprocessor(base64image,[512,512])
    prediction = model.predict(img)
    print(os.path.basename(image_path))
    print(prediction)
    preds = class_labels[np.argmax(prediction)]
    print(preds)
    print('\n')



####
Dockerfile
FROM python:3.10-slim-buster

WORKDIR /app
ADD . /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
RUN apt-get update && apt-get install -y python3-opencv
RUN pip install opencv-python

COPY . .

RUN [ "python3", "readme.py" ]

좋은 웹페이지 즐겨찾기