Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edit to warping file #1

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
067ff56
Add files via upload
nikitach5 Jun 10, 2021
1189cfa
Add files via upload
nikitach5 Jun 10, 2021
959c662
Add files via upload
nikitach5 Jun 10, 2021
25d9bd9
Delete Data_exploration.ipynb
nikitach5 Jun 10, 2021
c96a6ae
Add files via upload
nikitach5 Jun 10, 2021
13a5291
Delete DataExploration .ipynb
nikitach5 Jun 10, 2021
eca91a8
Merge branch 'harpArk614:master' into master
nikitach5 Jun 16, 2021
3cca9c1
Rename Data_Exploration.ipynb to Task1/Data_Exploration.ipynb
nikitach5 Jun 16, 2021
36666a9
Rename ResNet_Arch.ipynb to Task1/ResNet_Arch.ipynb
nikitach5 Jun 16, 2021
e7860f7
Update warping_module.py
nikitach5 Jun 26, 2021
22bba01
Update warping_module.py
nikitach5 Jun 26, 2021
4cf50a8
Update warping_module.py
nikitach5 Jun 26, 2021
e0dd536
Update utils.py
nikitach5 Jun 29, 2021
793d5ad
Create utils.py
nikitach5 Jun 29, 2021
8b964df
Update and rename models.py to model.py
nikitach5 Jul 29, 2021
65db8e3
Update decoder.py
nikitach5 Jul 29, 2021
02f99c5
Create decoder.py
nikitach5 Jul 29, 2021
03b15ec
Update encoder.py
nikitach5 Jul 29, 2021
c7f9e54
Update loss.py
nikitach5 Jul 29, 2021
b3ebab8
Update params.py
nikitach5 Jul 29, 2021
ddd1e08
Update dataset.py
nikitach5 Jul 29, 2021
9c584a6
Update warping_module.py
nikitach5 Jul 29, 2021
dcb5502
Delete utils.py
nikitach5 Jul 29, 2021
7576e7d
Add files via upload
nikitach5 Jul 29, 2021
5295376
Rename warpping_module3d.py to warping_module3d.py
nikitach5 Jul 29, 2021
aca3098
Add files via upload
nikitach5 Jul 29, 2021
935f25d
Add files via upload
nikitach5 Jul 29, 2021
22bdaf7
Add files via upload
nikitach5 Jul 29, 2021
59bb8b9
Add files via upload
nikitach5 Jul 29, 2021
3dd1d92
Add files via upload
nikitach5 Jul 29, 2021
650e05a
Add files via upload
nikitach5 Jul 29, 2021
fe0a181
Add files via upload
nikitach5 Jul 29, 2021
aacab58
Add files via upload
nikitach5 Jul 29, 2021
ee23738
Add files via upload
nikitach5 Jul 29, 2021
a43b59d
Add files via upload
nikitach5 Jul 29, 2021
ee7eae6
Add files via upload
nikitach5 Jul 29, 2021
5d30b91
Add files via upload
nikitach5 Jul 29, 2021
aa5a740
Add files via upload
nikitach5 Jul 29, 2021
9b0f219
Add files via upload
nikitach5 Jul 29, 2021
567d499
Rename main.py to pose3d_minimal/main.py
nikitach5 Jul 29, 2021
dfc99c2
Rename resnet_v2.py to pose3d_minimal/resnet_v2.py
nikitach5 Jul 29, 2021
e8487c4
Rename tfutil.py to pose3d_minimal/tfutil.py
nikitach5 Jul 29, 2021
fccd118
Rename resnet_utils.py to pose3d_minimal/resnet_utils.py
nikitach5 Jul 29, 2021
883f511
Add files via upload
nikitach5 Jul 29, 2021
2bc97a2
Create poses.pkl
nikitach5 Jul 29, 2021
eabadd0
Rename poses.pkl to po
nikitach5 Jul 29, 2021
e233e20
Delete poses.pkl
nikitach5 Jul 29, 2021
787f53e
Add files via upload
nikitach5 Jul 29, 2021
53a92fd
Update warping_module3d.py
nikitach5 Jul 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions Alternate_Dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import numpy as np
import tensorflow as tf
import pickle
import matplotlib.pyplot as plt
from matplotlib import image
import glob
import os
from PIL import Image
from numpy import asarray
import PIL
import pathlib
import tensorflow_datasets as tfds
# import tensorflow.keras.datasets.cifar10 as cf

from google.colab import drive
drive.mount('/content/gdrive')

# !unzip '/content/gdrive/MyDrive/In-shop Clothes Retrieval Benchmark/Img/img.zip'

infile = open('/content/gdrive/MyDrive/poses_fashion3d.pkl','rb')
poses = pickle.load(infile)

poses['MEN']['Denim']

poses['MEN']['Denim']['id_00007216']['01']['7_additional']

#Function For Converting image into numpy array

def img_to_tensor (path):
# load the image
image = Image.open(path)
# convert image to numpy array
data = asarray(image)
# print(type(data))
# # summarize shape
# print(data.shape)

# # create Pillow image
# image2 = Image.fromarray(data)
# print(type(image2))

# # summarize image details
# print(image2.mode)
# print(image2.size)
data.reshape(256,256,3)
return data

img_to_tensor('img/MEN/Denim/id_00000080/01_1_front.jpg')

data = {}
for n in poses:
for i in poses[n]:
#data_men[i] = {}
for j in poses[n][i]:
#data_men[i][j]={}
for k in poses[n][i][j]:
#data_men[i][j][k]={}
for l in poses[n][i][j][k]:
#data_men[i][j][k][l]={}
#for m in poses[n][i][j][k][l]:
#/img/MEN/Denim/id_00000182/01_1_front.jpg
path = 'img/'+n+'/'+i+'/'+j+'/'+k+'_'+l+'.jpg'

x = img_to_tensor(path)
data.update({path : x})

#x = img_to_tensor(path)
#data_men[i][j][k][l]=x

# print(data["img/MEN/Denim/id_00000080/01_7_additional.jpg"])

# !mkdir Dataset

# !cd Dataset

tstImg2=np.round(np.array(Image.open('img/MEN/Denim/id_00000080/01_1_front.jpg')).convert('RGB').resize((224,224)),dtype=np.float32)

tf.reshape(tstImg2, shape=[-1, 224, 224, 3])

def my_func(arg):
arg = tf.convert_to_tensor(arg, dtype=tf.float32)
return arg

tensor2=tf.io.decode_image(
'/content/img/MEN/Denim/id_00000080/01_1_front.jpg'
)

# img=Image.open('/content/img/MEN/Denim/id_00000080/01_1_front.jpg')
# array = tf.keras.preprocessing.image.img_to_array(img)

# print(array)

data = image.imread('/content/img/MEN/Denim/id_00000080/01_1_front.jpg')
plt.imshow(data)

# len(data_pose)

joint_order=['neck', 'nose', 'lsho', 'lelb', 'lwri', 'lhip', 'lkne', 'lank', 'rsho', 'relb', 'rwri', 'rhip', 'rkne', 'rank', 'leye', 'lear', 'reye', 'rear', 'pelv']

def give_name_to_keypoints(array, joint_order):
#array = array.T
res = {}
for i, name in enumerate(joint_order):
res[name] = array[i]
return res

for i, name in enumerate(joint_order):
print(i,name)

path="img/MEN/Denim/id_00000080/01_7_additional.jpg"
# print(data_pose.get(path))
print(data.get(path))

data_with_joints={}
for path,image in data.items():
array=data.get(path)
data_with_joints[path]=give_name_to_keypoints(array, joint_order)

data_with_joints["img/MEN/Denim/id_00000080/01_7_additional.jpg"]['lsho']

img_men = tf.keras.preprocessing.image_dataset_from_directory(
'img/MEN',
image_size=(256, 256),
labels = 'inferred'
)

type(img_men)

img_men_training = tf.keras.preprocessing.image_dataset_from_directory(
'img/MEN',
validation_split=0.2,
subset="training",
seed=123,
image_size=(256, 256),
labels = 'inferred'
)
399 changes: 399 additions & 0 deletions Task1/Data_Exploration.ipynb

Large diffs are not rendered by default.

925 changes: 925 additions & 0 deletions Task1/ResNet_Arch.ipynb

Large diffs are not rendered by default.

117 changes: 117 additions & 0 deletions adapted_resnet_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

# THIS CODE WAS HEAVILY ADAPTED AND DOES NOT CORRESPOND TO THE ORIGINAL TENSORFLOW IMPLEMENTATION

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import collections
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim

slim = contrib_slim


class Block(collections.namedtuple('Block', ['scope', 'unit_fn', 'args'])):
pass


def subsample(inputs, factor, scope=None):
if factor == 1:
return inputs
else:
return slim.max_pool2d(inputs, [1, 1], stride=factor, scope=scope)


def conv2d_same(inputs, num_outputs, kernel_size, stride, rate=1, scope=None):
if stride == 1:
return slim.conv2d(inputs, num_outputs, kernel_size, stride=1, rate=rate,
padding='SAME', scope=scope)
else:
kernel_size_effective = kernel_size + (kernel_size - 1) * (rate - 1)
pad_total = kernel_size_effective - 1
pad_beg = pad_total // 2
pad_end = pad_total - pad_beg
inputs = tf.pad(inputs,
[[0, 0], [pad_beg, pad_end], [pad_beg, pad_end], [0, 0]])
return slim.conv2d(inputs, num_outputs, kernel_size, stride=stride,
rate=rate, padding='VALID', scope=scope)


@slim.add_arg_scope
def stack_blocks_dense(net, blocks, output_stride=None,
store_non_strided_activations=False,
outputs_collections=None):
current_stride = 1

rate = 1

for block in blocks:
with tf.variable_scope(block.scope, 'block', [net]) as sc:
block_stride = 1
for i, unit in enumerate(block.args):
if store_non_strided_activations and i == len(block.args) - 1:
block_stride = unit.get('stride', 1)
unit = dict(unit, stride=1)

with tf.variable_scope('unit_%d' % (i + 1), values=[net]):
if output_stride is not None and current_stride == output_stride:
net = block.unit_fn(net, rate=rate, **dict(unit, stride=1))
rate *= unit.get('stride', 1)

else:
net = block.unit_fn(net, rate=1, **unit)
current_stride *= unit.get('stride', 1)
if output_stride is not None and current_stride > output_stride:
raise ValueError('The target output_stride cannot be reached.')

net = slim.utils.collect_named_outputs(outputs_collections, sc.name, net)

if output_stride is not None and current_stride == output_stride:
rate *= block_stride
else:
net = subsample(net, block_stride)
current_stride *= block_stride
if output_stride is not None and current_stride > output_stride:
raise ValueError('The target output_stride cannot be reached.')

if output_stride is not None and current_stride != output_stride:
raise ValueError('The target output_stride cannot be reached.')

return net


def resnet_arg_scope(weight_decay=0.0001,
batch_norm_epsilon=1e-5,
batch_norm_scale=True,
activation_fn=tf.nn.relu,
use_batch_norm=True):
batch_norm_params = {
'epsilon': batch_norm_epsilon,
'scale': batch_norm_scale
}

with slim.arg_scope(
[slim.conv2d],
weights_regularizer=slim.l2_regularizer(weight_decay),
weights_initializer=slim.variance_scaling_initializer(),
activation_fn=activation_fn,
normalizer_fn=slim.group_norm if use_batch_norm else None,
normalizer_params=batch_norm_params):
with slim.arg_scope([slim.group_norm], **batch_norm_params):
with slim.arg_scope([slim.max_pool2d], padding='SAME') as arg_sc:
return arg_sc
Loading