示例#1
0
def depth_predict(opt, image_pathfile='data/depth.txt'):
    # opt = TrainOptions().parse()  # set CUDA_VISIBLE_DEVICES before import torch
    with open(image_pathfile, 'r') as img_file:
        img = cv2.imread(img_file.read())
    img_shape = [img.shape[0], img.shape[1]]
    # print('shape of image:', img_shape)
    video_data_loader = aligned_data_loader.DAVISDataLoader(
        image_pathfile, BATCH_SIZE)
    video_dataset = video_data_loader.load_data()
    model = pix2pix_model.Pix2PixModel(opt)
    torch.backends.cudnn.enabled = False
    torch.backends.cudnn.benchmark = False
    model.switch_to_eval()
    save_path = 'data/outputs/'
    for i, data in enumerate(video_dataset):
        print(i)
        stacked_img = data[0]
        targets = data[1]
        pred_d_m = model.run_and_save_DAVIS(stacked_img, targets, save_path,
                                            img_shape)

    return pred_d_m


# depth = depth_predict()
示例#2
0
def run():
    # Windows用に追加
    torch.multiprocessing.freeze_support()

    opt = TrainVmdOptions().parse(
    )  # set CUDA_VISIBLE_DEVICES before import torch

    video_list = 'test_data/test_davis_video_list2.txt'

    eval_num_threads = 2
    video_data_loader = aligned_data_loader.DAVISDataLoader(
        video_list, BATCH_SIZE)
    video_dataset = video_data_loader.load_data()
    print('========================= Video dataset #images = %d =========' %
          len(video_data_loader))

    model = pix2pix_model.Pix2PixModel(opt)

    torch.backends.cudnn.enabled = True
    torch.backends.cudnn.benchmark = True
    best_epoch = 0
    global_step = 0

    print(
        '=================================  BEGIN VALIDATION ====================================='
    )

    print('TESTING ON VIDEO')

    model.switch_to_eval()
    save_path = 'test_data/viz_predictions/'
    print('save_path %s' % save_path)

    for i, data in enumerate(video_dataset):
        print(i)
        stacked_img = data[0]
        targets = data[1]
        model.run_and_save_DAVIS_test(stacked_img, targets, save_path)
# See the License for the specific language governing permissions and
# limitations under the License.

import torch
from options.train_options import TrainOptions
from loaders import aligned_data_loader
from models import pix2pix_model

BATCH_SIZE = 1

opt = TrainOptions().parse()  # set CUDA_VISIBLE_DEVICES before import torch

video_list = 'test_data/test_davis_video_list.txt'

eval_num_threads = 2
video_data_loader = aligned_data_loader.DAVISDataLoader(video_list, BATCH_SIZE)
video_dataset = video_data_loader.load_data()
print('========================= Video dataset #images = %d =========' %
      len(video_data_loader))

model = pix2pix_model.Pix2PixModel(opt)

torch.backends.cudnn.enabled = True
torch.backends.cudnn.benchmark = True
best_epoch = 0
global_step = 0

print(
    '=================================  BEGIN VALIDATION ====================================='
)
def main():
    config = {
        "apiKey": "AIzaSyBkQ5z8Rs5IRP4lHoiWyXV9XVQHjAh-sEI",
        "authDomain": "a-eye-for-the-blind.firebaseapp.com",
        "storageBucket": "a-eye-for-the-blind.appspot.com",
        "databaseURL":
        "https://a-eye-for-the-blind-default-rtdb.firebaseio.com/",
    }
    uid = "^^^^^^^^^^^"  # unique user ID, must set before running
    email = '*****@*****.**'
    password = '******'
    firebase = Firebase(config)
    db = firebase.database()
    auth = firebase.auth()
    storage = firebase.storage()

    user = auth.sign_in_with_email_and_password(email, password)
    user = auth.refresh(user['refreshToken'])

    if uid == "" or email == "" or password == "":
        print("Please set user UID, email, or password in the lines above!")
        sys.exit()

    engine = pyttsx3.init()
    BATCH_SIZE = 1
    eval_num_threads = 2
    opt = TrainOptions().parse(
    )  # set CUDA_VISIBLE_DEVICES before import torch
    model = pix2pix_model.Pix2PixModel(opt)
    torch.backends.cudnn.enabled = True
    torch.backends.cudnn.benchmark = True
    best_epoch = 0
    global_step = 0
    model.switch_to_eval()
    video_list = 'D:/A-Eye For The Blind/2dtodepth/infile1/'
    save_path = 'D:/A-Eye For The Blind/2dtodepth/outfile/'
    uid = 'yQowLXfAMddiITuMFASMoKlSGyh1'
    # initialize the camera
    cam = cv2.VideoCapture(cv2.CAP_DSHOW)  # 0 -> index of camera
    x = 0
    while True:
        s, img = cam.read()
        cv2.imwrite("D:/A-Eye For The Blind/2dtodepth/infile1/filename.jpg",
                    img)  # save image
        # filename = uid + ' ' + time()
        storage.child(f"images/i{str(x)}.jpg").put(
            "D:/A-Eye For The Blind/2dtodepth/infile1/filename.jpg",
            user['idToken'])
        url = storage.child(f"images/i{str(x)}.jpg").get_url(user['idToken'])
        data = {f"i{str(x)}": f"{url}"}
        db.child(f"users/{uid}").child("images").update(data)
        video_data_loader = aligned_data_loader.DAVISDataLoader(
            video_list, BATCH_SIZE)
        video_dataset = video_data_loader.load_data()
        for i, data in enumerate(video_dataset):
            stacked_img = data[0]
            targets = data[1]
            output = model.run_and_save_DAVIS(stacked_img, targets, save_path)
            height, width, _ = output.shape
            width_cutoff = width // 2
            half1 = output[:, :width_cutoff]
            half2 = output[:, width_cutoff:]
            width_cutoff = width // 4
            s1 = half1[:, :width_cutoff]
            s2 = half1[:, width_cutoff:]
            s3 = half2[:, :width_cutoff]
            s4 = half2[:, width_cutoff:]
            commands = finalcommand(s1, s2, s3, s4)
            print(commands)
            if commands[1] == 0:
                if commands[0] == 0 and commands[2] == 0:
                    engine.say("STOP!")
                elif commands[0] == 0:
                    engine.say("Move right.")
                elif commands[2] == 2:
                    engine.say("Move left.")
                else:
                    engine.say("Move left.")
            engine.runAndWait()
        os.remove("D:/A-Eye For The Blind/2dtodepth/infile1/filename.jpg")
        x += 1
        if cv2.waitKey(33) == ord('a'):
            break
    cam.release()