示例#1
0
def virtual_tryon(user_id,selected_id):
    f = open("./Database/val_pairs.txt" , "w")    
    f.write(user_id+".jpg "+selected_id+"_1.jpg")
    f.close()
    predict()
    im = Image.open("./output/second/TOM/val/" + selected_id + "_1.jpg")
    width, height = im.size  
    
    # Setting the points for cropped image  
    left = width / 3
    top = 2 * height / 3
    right = 2 * width / 3
    bottom = height
    
    # Cropped image of above dimension  
    # (It will not change orginal image)  
    im1 = im.crop((left, top, right, bottom)) 
    newsize = (200, 300) 
    im1 = im1.resize(newsize) 
    result_url="/output/second/TOM/val/" + selected_id + user_id + ".jpg"
    im1.save("."+result_url)
    return result_url
    def get(self):
        lines = request.get_json(force=True)
        ligid = lines[int1]
        seqid = lines[int2]
        
        # TODO parse out 2 ints from json

        s = f"prediction at ({ligid},{seqid}): {predict(ligid, seqid)}"
        #s = str(predict(5,5))
        x = predict(ligid, seqid)
        print(s)
        return {'RESULT': str(x), 
                'report': s,
                'show_inp': str(ligid) + str(seqid)}
示例#3
0
def index(request):
    # Get common and all the symptoms from data set
    raw_data_common, raw_data_all = getData()

    # Split symptoms name by underscrore(_)
    common_symptom = []
    all_symptom = []
    for i in raw_data_common:
        tmp = i.split('_', 1)[-1]
        common_symptom.append(tmp)

    for i in raw_data_all:
        tmp = i.split('_', 1)[-1]
        all_symptom.append(tmp)

    data = list(zip(raw_data_common, common_symptom))
    data1 = list(zip(raw_data_all, all_symptom))

    if request.method == 'POST' and 'train_data' in request.POST:
        # Run training function when Train button is clicked
        sys.path.append('..')
        from script import training
        training()

    if request.method == 'POST' and 'predict_disease' in request.POST:
        # Get symptoms list and prepare them for input
        checked_list = request.POST.getlist('checks[]')
        symptoms_set = request.POST.get("symptoms_field")
        symptoms_list = symptoms_set.split(",")
        merged_list = symptoms_list + checked_list
        merged_list = list(set(merged_list))
        print("\nInput are : \n", merged_list)

        # When no symptoms is selected
        if all('' == s or s.isspace() for s in merged_list):
            print("\nInput is empty:\n")
            return render(request, "home.html", {"data": data, "data1": data1})

        # Feed input list to predict function to generate prediction output
        sys.path.append('..')
        from script import predict
        values = predict(merged_list)
        print("\nOutput are:\n", values, "\n")
        return render(request, "home.html", {
            "data": data,
            "data1": data1,
            "predicted_diseases": values
        })

    return render(request, "home.html", {"data": data, "data1": data1})
示例#4
0
def final_img():
    global name, selection
    person = Image.open('temp.jpg')
    person.save("./Database/val/person/" + name + ".jpg")
    pose_parse(name)
    execute()
    f = open("./Database/val_pairs.txt", "w")
    f.write(name + ".jpg " + selection + "_1.jpg")
    f.close()
    predict()
    im = Image.open("./output/second/TOM/val/" + selection + "_1.jpg")
    width, height = im.size
    left = width / 3
    top = 2 * height / 3
    right = width
    bottom = height
    im1 = im.crop((left, top, right, bottom))
    newsize = (600, 450)
    im1 = im1.resize(newsize)
    im1.save("./output/second/TOM/val/" + selection + "_1.jpg")
    result = Image.open("./output/second/TOM/val/" + selection + "_1.jpg")
    result.save("data.jpg")
    return Response(gen_stored("data.jpg"),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
示例#5
0
    progress_bar = st.progress(0)
    st.write("Generating Mask and Pose Pairs")
    pose_parse(user_input)
    execute()
    for percent_complete in range(100):
        time.sleep(0.05)
        progress_bar.progress(percent_complete + 1)
    st.write(
        "Please click the Click Button after Pose pairs and Masks are generated"
    )

if st.button('Execute'):
    f = open("./Database/val_pairs.txt", "w")
    f.write(user_input + ".jpg " + selected + "_1.jpg")
    f.close()
    predict()
    from PIL import Image
    im = Image.open("./output/second/TOM/val/" + selected + "_1.jpg")
    width, height = im.size

    # # Setting the points for cropped image
    left = width / 3
    top = 2 * height / 3
    right = 2 * width / 3
    bottom = height

    # # Cropped image of above dimension
    # # (It will not change orginal image)
    im1 = im.crop((left, top, right, bottom))
    newsize = (100, 150)
    im1 = im1.resize(newsize)
示例#6
0
def upload_image4():
	cache.init_app(app2)
	with app2.app_context():
			cache.clear()
	party_cloth = ['000003' , '000108', '001719' ,'017376' ,'000178', '000182' , '001428' , '004710' , '008632' , '017374','002061', '017642', '017377', '017963', '018348', '019067','019564', '017643']
	for i in range(len(party_cloth)):
		party_cloth[i] = (str(party_cloth[i])+"_1.jpg")

	if request.method=="POST":
		# if 'file' not in request.files:
		# 	flash('No file part')
		# 	return redirect(request.url)
		
		text = request.form['input_text']
		file = request.files['file']
		
		if file.filename == '':
			flash('No image selected for uploading')
			return redirect(request.url)
		
		if file and allowed_file(file.filename) and text:
			filename = secure_filename(file.filename)
			file.save(os.path.join(app.config['UPLOAD_FOLDER1'], filename))
			i_path = 'static/Database/val/person/'
			input_img = text+'.jpg'
			os.rename(i_path+filename , i_path+input_img)
			filename = text+'.jpg'
			o_path = './output/second/TOM/val'
			# fish = glob.glob('./output/second/TOM/val/*')
			fish = glob.glob('./static/output_f/*')
			for f in fish:
				os.remove(f)
			time.sleep(10)			#
			#
			#
			# 
			pose_parse(text)
			valpair_file = 'static/Database/val_pairs.txt'
			
			for i in range(len(party_cloth)):
				with open(valpair_file , "w") as f:
						f.write(text+'.jpg '+ party_cloth[i] )
						f.close()
						predict()
						im = Image.open(os.path.join(o_path,party_cloth[i]))
						width, height = im.size
						left = width / 3
						top = 2 * height / 3
						right = 2 * width / 3
						bottom = height
						im = im.crop((left, top, right, bottom)) 
						newsize = (200, 270) 
						im = im.resize(newsize)
						im.save(os.path.join(app2.config['OUTPUT_FOLDER3'],party_cloth[i]))
			#
			#
			#
			return render_template('party_wear.html', party=party_cloth, text= text)
		else:
			flash('Allowed image types are -> png, jpg, jpeg, gif')
			return redirect(request.url)
	return render_template('party_wear.html')
parser.add_argument('--top_k', action="store", default=5, dest="top_k",  type=int)
parser.add_argument('--gpu', action='store_true', default=False, dest='gpu', help='Set a switch to use GPU')
results = parser.parse_args()

img_path = results.img_path
checkpoint_path = results.ck_path
category_names = results.category_names
top_k = results.top_k
gpu = results.gpu

if gpu==True:
    using_gpu = torch.cuda.is_available()
    device = 'gpu'
    print('GPU On');
else:
    print('GPU Off');
    device = 'cpu'

model = script.loading_checkpoint(checkpoint_path)
processed_image = script.process_image(img_path)
probs, classes = script.predict(processed_image, model, top_k, device)

# Label mapping
cat_to_name = script.labeling(category_names)
labels = []
for class_index in classes:
    labels.append(cat_to_name[str(class_index)])

# Converting from tensor to numpy-array
print('Name of class: ', labels[0])
print('Probability: ', probs)
示例#8
0
def upload_image5():
    cache.init_app(app2)
    with app2.app_context():
        cache.clear()
    fish = glob.glob('./static/Database/val/person/*')
    for f in fish:
        os.remove(f)
    fish = glob.glob('./static/size/*')
    for f in fish:
        os.remove(f)
    tshirt = [
        'POLO_Black', 'POLO-blue', 'POLO-Blue', 'POLO-BLue', 'POLO-orach',
        'POLO-Violet'
    ]
    for i in range(len(tshirt)):
        tshirt[i] = (str(tshirt[i]) + ".jpg")

    if request.method == "POST":
        text = "tshirtss"
        file = request.files['file']
        file1 = request.files['file1']
        height = request.form['height']
        unit = request.form.get('unit')
        Go = "False"

        if file.filename == '':
            flash('No image uploaded for size prediction.')
            return redirect(request.url)

        if file1.filename == '':
            flash('No image uploaded for trying clothes.')
            return redirect(request.url)

        if file and allowed_file(file.filename) and file1 and allowed_file(
                file1.filename) and height and unit and text:
            filename = secure_filename(file.filename)
            filename1 = secure_filename(file1.filename)
            file1.save(os.path.join(app.config['UPLOAD_FOLDER2'], filename1))
            i_path = 'static/size/'
            file_path = os.path.join(i_path, filename1)
            size = women_size_predict(file_path, height, unit)
            #
            file.save(os.path.join(app.config['UPLOAD_FOLDER1'], filename))
            i_path = 'static/Database/val/person/'
            input_img = text + '.jpg'
            os.rename(i_path + filename, i_path + input_img)
            filename = text + '.jpg'
            o_path = './output/second/TOM/val'
            # time.sleep(10)			#
            #
            #
            #
            pose_parse(text)
            valpair_file = 'static/Database/val_pairs.txt'

            for i in range(len(tshirt)):
                with open(valpair_file, "w") as f:
                    f.write(text + '.jpg ' + tshirt[i])
                    f.close()
                    predict()
                    im = Image.open(os.path.join(o_path, tshirt[i]))
                    width, height = im.size
                    left = width / 3
                    top = 2 * height / 3
                    right = 2 * width / 3
                    bottom = height
                    im = im.crop((left, top, right, bottom))
                    newsize = (200, 270)
                    im = im.resize(newsize)
                    im.save(
                        os.path.join(app2.config['OUTPUT_FOLDER3'], tshirt[i]))
            #
            #
            #
            ##
            ##
            return render_template('tshirt.html',
                                   tshirt=tshirt,
                                   text=text,
                                   size=size)
        else:
            flash('Allowed image types are -> png, jpg, jpeg, gif')
            return redirect(request.url)
    return render_template('tshirt.html')
示例#9
0
def upload_image4():
    cache.init_app(app2)
    with app2.app_context():
        cache.clear()
    fish = glob.glob('./static/Database/val/person/*')
    for f in fish:
        os.remove(f)
    fish = glob.glob('./static/size/*')
    for f in fish:
        os.remove(f)
    party = [
        'Orach-Flayrd', 'MultiColor', 'Butterfly_p', 'Waved-Black', 'Shimm',
        'Wavy-Red', 'Wavy-Pink', 'Reddish-KNOTS'
    ]
    for i in range(len(party)):
        party[i] = (str(party[i]) + ".jpg")

    if request.method == "POST":

        text = "palty"
        file = request.files['file']
        height = request.form['height']
        unit = request.form.get('unit')
        Go = "False"

        if file.filename == '':
            flash('No image uploaded for trying clothes.')
            return redirect(request.url)

        if file and allowed_file(file.filename) and height and unit and text:
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER2'], filename))
            i_path = 'static/size/'
            file_path = os.path.join(i_path, filename)
            size, file = women_size_predict1(file_path, height, unit)
            file = Image.fromarray(file, 'RGB')
            #
            file.save(os.path.join(app.config['UPLOAD_FOLDER1'], filename))
            i_path = 'static/Database/val/person/'
            input_img = text + '.jpg'
            os.rename(i_path + filename, i_path + input_img)
            filename = text + '.jpg'
            o_path = './output/second/TOM/val'
            # fish = glob.glob('./output/second/TOM/val/*')
            fish = glob.glob('./static/outputs/output_f/*')
            for f in fish:
                os.remove(f)
            time.sleep(10)  #
            #
            #
            #
            pose_parse(text)
            valpair_file = 'static/Database/val_pairs.txt'

            for i in range(len(party)):
                with open(valpair_file, "w") as f:
                    f.write(text + '.jpg ' + party[i])
                    f.close()
                    predict()
                    im = Image.open(os.path.join(o_path, party[i]))
                    width, height = im.size
                    left = width / 3
                    top = 2 * height / 3
                    right = 2 * width / 3
                    bottom = height
                    im = im.crop((left, top, right, bottom))
                    newsize = (200, 270)
                    im = im.resize(newsize)
                    im.save(
                        os.path.join(app2.config['OUTPUT_FOLDER3'], party[i]))
            #
            #
            #
            ##
            ##
            return render_template('party_wear.html',
                                   party=party,
                                   text=text,
                                   size=size)
        else:
            flash('Allowed image types are -> png, jpg, jpeg, gif')
            return redirect(request.url)
    return render_template('party_wear.html')
示例#10
0
def upload_image3():
    cache.init_app(app2)
    with app2.app_context():
        cache.clear()
    fish = glob.glob('./static/Database/val/person/*')
    for f in fish:
        os.remove(f)
    fish = glob.glob('./static/size/*')
    for f in fish:
        os.remove(f)
    brand_cloth = [
        'Pink-Flayrd', 'Blue-flayrd', 'Flayerd-Yellow', 'Bluish-Flayrd',
        'NIKE-black', 'RED-Flayrd'
    ]  #'
    for i in range(len(brand_cloth)):
        brand_cloth[i] = (str(brand_cloth[i]) + ".jpg")

    if request.method == "POST":

        text = "brandss"
        file = request.files['file']
        height = request.form['height']
        unit = request.form.get('unit')

        if file.filename == '':
            flash('No image selected for uploading')
            return redirect(request.url)

        if file and allowed_file(file.filename) and height and unit:
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER2'], filename))
            i_path = 'static/size/'
            file_path = os.path.join(i_path, filename)
            size, file = women_size_predict1(file_path, height, unit)
            file = Image.fromarray(file, 'RGB')
            #
            file.save(os.path.join(app.config['UPLOAD_FOLDER1'], filename))
            i_path = 'static/Database/val/person/'
            input_img = text + '.jpg'
            os.rename(i_path + filename, i_path + input_img)
            filename = text + '.jpg'
            o_path = './output/second/TOM/val'
            # fish = glob.glob('./output/second/TOM/val/*')
            fish = glob.glob('./static/outputs/output_f/*')
            for f in fish:
                os.remove(f)
            time.sleep(10)
            #
            #
            #
            #
            pose_parse(text)
            valpair_file = 'static/Database/val_pairs.txt'

            for i in range(len(brand_cloth)):
                with open(valpair_file, "w") as f:
                    f.write(text + '.jpg ' + brand_cloth[i])
                    f.close()
                    predict()
                    im = Image.open(os.path.join(o_path, brand_cloth[i]))
                    width, height = im.size
                    left = width / 3
                    top = 2 * height / 3
                    right = 2 * width / 3
                    bottom = height
                    im = im.crop((left, top, right, bottom))
                    newsize = (200, 270)
                    im = im.resize(newsize)
                    im.save(
                        os.path.join(app2.config['OUTPUT_FOLDER3'],
                                     brand_cloth[i]))
            #
            #
            #
            return render_template('brands.html',
                                   brands=brand_cloth,
                                   text=text,
                                   size=size)
        else:
            flash('Allowed image types are -> png, jpg, jpeg, gif')
            return redirect(request.url)
    return render_template('brands.html')
示例#11
0
def upload_image2():
    cache.init_app(app2)
    with app2.app_context():
        cache.clear()
    fish = glob.glob('./static/Database/val/person/*')
    for f in fish:
        os.remove(f)
    fish = glob.glob('./static/size/*')
    for f in fish:
        os.remove(f)
    sport_cloth = [
        'ADIDAS-BW', 'ADIDAS_Black', 'FILA_grey', 'FILA-Pink', 'IVY-Black',
        'NIKE-grey'
    ]
    for i in range(len(sport_cloth)):
        sport_cloth[i] = (str(sport_cloth[i]) + ".jpg")

    if request.method == "POST":
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)

        text = "sportss"
        file = request.files['file']
        height = request.form['height']
        unit = request.form.get('unit')
        Go = "False"

        if file.filename == '':
            flash('No image uploaded for size prediction.')
            return redirect(request.url)

        if file and allowed_file(file.filename) and height and unit:
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER2'], filename))
            i_path = 'static/size/'
            file_path = os.path.join(i_path, filename)
            size, file = women_size_predict1(file_path, height, unit)
            file = Image.fromarray(file, 'RGB')
            #
            file.save(os.path.join(app.config['UPLOAD_FOLDER1'], filename))
            i_path = 'static/Database/val/person/'
            input_img = text + '.jpg'
            os.rename(i_path + filename, i_path + input_img)
            filename = text + '.jpg'
            o_path = './output/second/TOM/val'
            # fish = glob.glob('./output/second/TOM/val/*')
            fish = glob.glob('./static/outputs/output_f/*')
            for f in fish:
                os.remove(f)
            time.sleep(10)
            #
            #
            #
            #
            pose_parse(text)
            valpair_file = 'static/Database/val_pairs.txt'

            for i in range(len(sport_cloth)):
                with open(valpair_file, "w") as f:
                    f.write(text + '.jpg ' + sport_cloth[i])
                    f.close()
                    predict()
                    im = Image.open(os.path.join(o_path, sport_cloth[i]))
                    width, height = im.size
                    left = width / 3
                    top = 2 * height / 3
                    right = 2 * width / 3
                    bottom = height
                    im = im.crop((left, top, right, bottom))
                    newsize = (200, 270)
                    im = im.resize(newsize)
                    im.save(
                        os.path.join(app2.config['OUTPUT_FOLDER3'],
                                     sport_cloth[i]))
            #
            #
            #
            return render_template('sports.html',
                                   sports=sport_cloth,
                                   text=text,
                                   size=size)
        else:
            flash('Allowed image types are -> png, jpg, jpeg, gif')
            return redirect(request.url)
    return render_template('sports.html')
示例#12
0
def upload_image():
    cache.init_app(app2)
    with app2.app_context():
        cache.clear()
    fish = glob.glob('./static/Database/val/person/*')
    for f in fish:
        os.remove(f)
    fish = glob.glob('./static/size/*')
    for f in fish:
        os.remove(f)
    cloth = [
        'Casual-Yellow', 'Casual-Pink', 'Casual-Violet', 'Casual-White',
        'Dark_ORANGE', 'Flowers-White', 'Grey_North', 'Light-Pink',
        'Multicolo-White', 'Sky_Blue', 'TheNORTHface', 'Yellow62'
    ]
    for i in range(len(cloth)):
        cloth[i] = (str(cloth[i]) + ".jpg")

    if request.method == "POST":
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)

        text = "casualss"
        file = request.files['file']
        height = request.form['height']
        unit = request.form.get('unit')

        if file.filename == '':
            flash('No image selected for uploading')
            return redirect(request.url)

        if file and allowed_file(file.filename) and text and height and unit:
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER2'], filename))
            i_path = 'static/size/'
            file_path = os.path.join(i_path, filename)
            size, file = women_size_predict1(file_path, height, unit)
            file = Image.fromarray(file, 'RGB')
            #
            file.save(os.path.join(app.config['UPLOAD_FOLDER1'], filename))
            i_path = 'static/Database/val/person/'
            input_img = text + '.jpg'
            os.rename(i_path + filename, i_path + input_img)
            filename = text + '.jpg'
            o_path = './output/second/TOM/val'
            # fish = glob.glob('./output/second/TOM/val/*')
            fish = glob.glob('./static/outputs/output_f/*')
            for f in fish:
                os.remove(f)
            time.sleep(10)
            #
            #
            #
            #
            pose_parse(text)
            valpair_file = 'static/Database/val_pairs.txt'

            for i in range(len(cloth)):
                with open(valpair_file, "w") as f:
                    f.write(text + '.jpg ' + cloth[i])
                    f.close()
                    predict()
                    im = Image.open(os.path.join(o_path, cloth[i]))
                    width, height = im.size
                    left = width / 3
                    top = 2 * height / 3
                    right = 2 * width / 3
                    bottom = height
                    im = im.crop((left, top, right, bottom))
                    newsize = (200, 270)
                    im = im.resize(newsize)
                    im.save(
                        os.path.join(app2.config['OUTPUT_FOLDER3'], cloth[i]))
            #
            #
            #
            return render_template('casuals.html',
                                   casuals=cloth,
                                   text=text,
                                   size=size)
        else:
            flash('Allowed image types are -> png, jpg, jpeg, gif')
            return redirect(request.url)
    return render_template('casuals.html')